refactoring: macro for memset, memcpy, mov_word_mem

This commit is contained in:
giomba 2021-11-07 22:52:31 +01:00
parent 6e0d335b83
commit a8319e9fb7
3 changed files with 105 additions and 80 deletions

View File

@ -1,7 +1,5 @@
SEG zeropageSegment
; Generic src/dst copy pointers
srcPointer DS 2
dstPointer DS 2
introDestPtr WORD
SEG programSegment
introreset SUBROUTINE
@ -19,9 +17,9 @@ introreset SUBROUTINE
; for "GLGPROGRAMS" at the beginning
ldx #$78
stx dstPointer
stx introDestPtr
ldy #$04
sty dstPointer + 1
sty introDestPtr + 1
; GLGPROGRAMS color
ldy #$00
@ -57,29 +55,19 @@ statusIntro0 SUBROUTINE
and #$f8
sta $d011
ldy #0 ; ... clear text line ...
lda #$80
.clearLineLoop:
sta (dstPointer),y
iny
cpy #40
bne .clearLineLoop
MOV_WORD_MEM dstPointer, introDestPtr
MEMSET "D", #$80, #40
clc ; ... move dstPointer to next text line ...
lda dstPointer
clc ; ... move introDestPtr to next text line ...
lda introDestPtr
adc #40
sta dstPointer
lda dstPointer + 1
sta introDestPtr
lda introDestPtr + 1
adc #0
sta dstPointer + 1
sta introDestPtr + 1
ldy #$00 ; ... and copy "GLG Programs" text to next text line
.glgLoop:
lda GLGProgramsText,y
sta (dstPointer),y
iny
cpy #200
bne .glgLoop
MOV_WORD_MEM dstPointer, introDestPtr
MEMCPY "D", #GLGProgramsText, #200 ; ... and copy "GLG Programs" text to next text line
dec introYscroll ; remember that we are one line below
beq .next ; if we reached the end of the vertical scroll, advance status
@ -304,13 +292,7 @@ statusIntro4 SUBROUTINE
cmp #$02
bne .end
lda #$80
ldy #$0
.loop:
sta $540,y
iny
cpy #200
bne .loop
MEMSET #$540, #$80, #200
lda #ST_INTRO5
sta status
@ -426,36 +408,8 @@ statusMenuReset SUBROUTINE
bne .lastlineColorLoop
; Print Game Title: big "SNAKE"
; color first
MEMSET #$d800, #$02, #150
; actual "text"
lda #$00
sta dstPointer
lda #$04
sta dstPointer + 1
ldx #<SnakeText
ldy #>SnakeText
stx srcPointer
sty srcPointer + 1
ldy #$00
.SnakeTitleLoop:
lda (srcPointer),y
sta (dstPointer),y
inc srcPointer
bne .noinc1
inc srcPointer + 1
.noinc1:
inc dstPointer
bne .noinc2
inc dstPointer + 1
.noinc2:
lda dstPointer
cmp #$18
bne .SnakeTitleLoop
lda dstPointer + 1
cmp #$05
bne .SnakeTitleLoop
MEMSET #$d800, #$02, #280 ; color
MEMCPY #$400, #SnakeText, #280 ; text
; Print website
lda #<intro2string ; lsb of string address

View File

@ -1,30 +1,101 @@
SEG zeropageSegment
ptrDstStart WORD
ptrDstEnd WORD
; Generic src/dst copy pointers
srcPointer WORD
dstPointer WORD
dstPointerEnd WORD
SEG programSegment
MACRO MEMSET
IF {1} != "D"
clc
lda <{1}
sta ptrDstStart
adc <({3} + 1)
sta ptrDstEnd
sta dstPointer
adc <{3}
sta dstPointerEnd
lda >{1}
sta ptrDstStart + 1
adc >({3} + 1)
sta ptrDstEnd + 1
sta dstPointer + 1
adc >{3}
sta dstPointerEnd + 1
ELSE
clc
lda dstPointer
adc <{3}
sta dstPointerEnd
lda dstPointer + 1
adc >{3}
sta dstPointerEnd + 1
ENDIF
lda {2}
ldy #0
.loop:
sta (ptrDstStart),y
inc ptrDstStart
sta (dstPointer),y
inc dstPointer
bne .skipInc
inc ptrDstStart + 1
inc dstPointer + 1
.skipInc:
ldx ptrDstStart
cpx ptrDstEnd
ldx dstPointer
cpx dstPointerEnd
bne .loop
ldx ptrDstStart + 1
cpx ptrDstEnd + 1
ldx dstPointer + 1
cpx dstPointerEnd + 1
bne .loop
ENDM
SEG zeroPageSegment
SEG programSegment
MACRO MEMCPY
IF {1} != "D"
clc
lda <{1}
sta dstPointer
adc <{3}
sta dstPointerEnd
lda >{1}
sta dstPointer + 1
adc >{3}
sta dstPointerEnd + 1
ELSE
clc
lda dstPointer
adc <{3}
sta dstPointerEnd
lda dstPointer + 1
adc >{3}
sta dstPointerEnd + 1
ENDIF
lda <{2}
sta srcPointer
lda >{2}
sta srcPointer + 1
ldy #$0
.loop:
lda (srcPointer),y
sta (dstPointer),y
inc dstPointer
bne .skipIncDst
inc dstPointer + 1
.skipIncDst:
inc srcPointer
bne .skipIncSrc
inc srcPointer + 1
.skipIncSrc:
ldx dstPointer
cpx dstPointerEnd
bne .loop
ldx dstPointer + 1
cpx dstPointerEnd + 1
bne .loop
ENDM
SEG programSegment
MACRO MOV_WORD_MEM
lda {2}
sta {1}
lda {2} + 1
sta {1} + 1
ENDM

View File

@ -58,12 +58,12 @@ zeroFillZeroPage:
lda #ST_INTRO0
sta status
; Enable interrupts
cli
; Reset screen (and other parameters) to play intro
jsr introreset
; Enable interrupts
cli
menu SUBROUTINE
.menu: ; Cycle here until SPACE or `Q` is pressed
jsr $ffe4 ; GETIN