Skip to content

Instantly share code, notes, and snippets.

@ped7g
Created January 10, 2021 09:27
Show Gist options
  • Save ped7g/2c281f22beb30e562c26cd7aca0f5154 to your computer and use it in GitHub Desktop.
Save ped7g/2c281f22beb30e562c26cd7aca0f5154 to your computer and use it in GitHub Desktop.
; to assemble: sjasmplus asterisk_vs_exclamation_char.asm
DEVICE ZXSPECTRUM48,31999 : OPT --zxnext
ORG $8000
font:
ASSERT 0 == high(font) % 8 ; must reside at aligned-enough address to fit this
ds '!'*8,0 ; don't bother to define other chars, go to exclamation mark
dg ---##---
dg ---##---
dg ---##---
dg ---##---
dg --------
dg ---##---
dg ---##---
dg --------
ds ('*'-'!'-1)*8,0 ; zero pixels filler between '!' and '*'
dg --------
dg --------
dg -#---#--
dg --#-#---
dg #######-
dg --#-#---
dg -#---#--
dg --------
start:
nextreg 7,3 ; 28MHz mode
ld de,$0000 ; x = 0, y = 0 [x,y] of char, but in pixel coordinates
; "in pixels" to make use of `pixelad` Z80N (ZX Next) instruction possible
; but the coordinates must still move by +-8 pixels because of the "print" code
ld b,8 ; dx = +8
ld c,'*' ; char to print
loop:
call printChar
; adjust x position
ld a,e
add a,b
jr z,.flipDirection ; if the new x pos would be zero, flip direction instead
ld e,a ; store the updated x position
jr loop
.flipDirection:
; flip direction and char
ld a,b
xor +8^-8 ; turn 8 into -8, and -8 into 8
ld b,a
ld a,c
xor '*'^'!' ; turn '*' into '!' and '!' into '*'
ld c,a
; keep DE as it was, to redraw the first/last character after flip
jr loop
printChar:
pixelad ; HL = pixel address of [D,E] coordinates
push de ; preserve coordinates in stack
ex de,hl ; DE = target address in video RAM (VRAM)
ld l,c
ld h,high(font)/8 ; HL = (char_font_data address)/8
.3 add hl,hl ; 3x HL = HL * 2 ; ergo HL = char_font_data address
.8 ldws ; 8x LDWS to draw the char
pop de ; restore char coordinates back into DE
ret
SAVESNA "nextspd.sna", start
CSPECTMAP "nextspd.map"
IFNDEF LAUNCH_EMULATOR : DEFINE LAUNCH_EMULATOR 0 : ENDIF
IF 0 == __ERRORS__ && 0 == __WARNINGS__ && 1 == LAUNCH_EMULATOR
SHELLEXEC "( sleep 0.1s ; runCSpect -brk -map=nextspd.map -w2 nextspd.sna ) &"
ENDIF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment