diff --git a/src/fx/fx.hgr.48boxes.a b/src/fx/fx.hgr.48boxes.a index 6887094e2..890602aa4 100644 --- a/src/fx/fx.hgr.48boxes.a +++ b/src/fx/fx.hgr.48boxes.a @@ -15,38 +15,38 @@ !byte $00,$FC,$F8,$F4,$F0,$EC,$E8,$E4 StagesHi ; high bytes of address of drawing routine for each stage - !byte >clear00 - !byte >clear01 - !byte >clear02 - !byte >clear03 - !byte >clear04 - !byte >clear05 - !byte >clear06 - !byte >clear07 - !byte >clear08 - !byte >clear09 - !byte >clear0A - !byte >clear0B - !byte >clear0C - !byte >clear0D - !byte >clear0E - !byte >clear0F + !byte clear00 + !byte clear01 + !byte clear02 + !byte clear03 + !byte clear04 + !byte clear05 + !byte clear06 + !byte clear07 + !byte clear08 + !byte clear09 + !byte clear0A + !byte clear0B + !byte clear0C + !byte clear0D + !byte clear0E + !byte clear0F !byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 !byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 - !byte >copy0F - !byte >copy0E - !byte >copy0D - !byte >copy0C - !byte >copy0B - !byte >copy0A - !byte >copy09 - !byte >copy08 - !byte >copy07 - !byte >copy06 - !byte >copy05 - !byte >copy04 - !byte >copy03 - !byte >copy02 - !byte >copy01 - !byte >copy00 + !byte copy0F + !byte copy0E + !byte copy0D + !byte copy0C + !byte copy0B + !byte copy0A + !byte copy09 + !byte copy08 + !byte copy07 + !byte copy06 + !byte copy05 + !byte copy04 + !byte copy03 + !byte copy02 + !byte copy01 + !byte copy00 EndStagesHi diff --git a/src/fx/fx.hgr.48boxes.common.a b/src/fx/fx.hgr.48boxes.common.a index 96ea93489..0dbcbd3c4 100644 --- a/src/fx/fx.hgr.48boxes.common.a +++ b/src/fx/fx.hgr.48boxes.common.a @@ -1,52 +1,175 @@ -;license:MIT +;License:MIT ;(c) 2020 by 4am & qkumba ; -src = $00 ; [word][must be at $00] -dst = $02 ; [word] -box = $04 ; [byte] -any = $05 ; [byte] -rowcount = $06 ; [byte] +; The screen is separated into 48 boxes. +; Boxes are laid out in a grid, left-to-right, top-down: +; +; 0 1 2 3 4 5 6 7 +; 8 9 10 11 12 13 14 15 +; 16 17 18 19 20 21 22 23 +; 24 25 26 27 28 29 30 31 +; 32 33 34 35 36 37 38 39 +; 40 41 42 43 44 45 46 47 +; +; Each box is 35x32 pixels, so each row of each box is 5 consecutive +; bytes in memory once you calculate the HGR base address for that row. +; +; |BoxInitialStages| defines the initial grid of stages for each box. +; Negative stages (80..FF) are no-ops. +; Positive stages (00..7F) are indexes into the |StagesHi| array +; to find the drawing routine for this stage (if any). +; Each box's stage is incremented after each iteration through the main loop. +; When the main loop iterates through all 48 boxes without drawing anything, +; the program exits. +; +; There are 16 clear routines that set certain bits to 0 (black), +; labeled clear00..clear0F. clear00 clears the inner-most box, and +; clear0F clears the outermost box (see diagram). +; There are 16 copy routines that copy certain bits from the source +; image on page 2 to the destination image on page 1, labeled copy00..copy0F. +; +; row| bits +; ---+--------------------------------------- +; 00 |FFFFFFF|FFFFFFF|FFFFFFF|FFFFFFF|FFFFFFF +; 01 |FEEEEEE|EEEEEEE|EEEEEEE|EEEEEEE|EEEEEEF +; 02 |FEDDDDD|DDDDDDD|DDDDDDD|DDDDDDD|DDDDDEF +; 03 |FEDCCCC|CCCCCCC|CCCCCCC|CCCCCCC|CCCCDEF +; 04 |FEDCBBB|BBBBBBB|BBBBBBB|BBBBBBB|BBBCDEF +; 05 |FEDCBAA|AAAAAAA|AAAAAAA|AAAAAAA|AABCDEF +; 06 |FEDCBA9|9999999|9999999|9999999|9ABCDEF +; 07 |FEDCBA9|8888888|8888888|8888888|9ABCDEF +; ---+-------+-------+-------+-------+------- +; 08 |FEDCBA9|8777777|7777777|7777778|9ABCDEF +; 09 |FEDCBA9|8766666|6666666|6666678|9ABCDEF +; 0A |FEDCBA9|8765555|5555555|5555678|9ABCDEF +; 0B |FEDCBA9|8765444|4444444|4445678|9ABCDEF +; 0C |FEDCBA9|8765433|3333333|3345678|9ABCDEF +; 0D |FEDCBA9|8765432|2222222|2345678|9ABCDEF +; 0E |FEDCBA9|8765432|1111111|2345678|9ABCDEF +; 0F |FEDCBA9|8765432|1000001|2345678|9ABCDEF +; ---+-------+-------+-------+-------+------- +; 10 |FEDCBA9|8765432|1000001|2345678|9ABCDEF +; 11 |FEDCBA9|8765432|1111111|2345678|9ABCDEF +; 12 |FEDCBA9|8765432|2222222|2345678|9ABCDEF +; 13 |FEDCBA9|8765433|3333333|3345678|9ABCDEF +; 14 |FEDCBA9|8765444|4444444|4445678|9ABCDEF +; 15 |FEDCBA9|8765555|5555555|5555678|9ABCDEF +; 16 |FEDCBA9|8766666|6666666|6666678|9ABCDEF +; 17 |FEDCBA9|8777777|7777777|7777778|9ABCDEF +; ---+-------+-------+-------+-------+------- +; 18 |FEDCBA9|8888888|8888888|8888888|9ABCDEF +; 19 |FEDCBA9|9999999|9999999|9999999|9ABCDEF +; 1A |FEDCBAA|AAAAAAA|AAAAAAA|AAAAAAA|AABCDEF +; 1B |FEDCBBB|BBBBBBB|BBBBBBB|BBBBBBB|BBBCDEF +; 1C |FEDCCCC|CCCCCCC|CCCCCCC|CCCCCCC|CCCCDEF +; 1D |FEDDDDD|DDDDDDD|DDDDDDD|DDDDDDD|DDDDDEF +; 1E |FEEEEEE|EEEEEEE|EEEEEEE|EEEEEEE|EEEEEEF +; 1F |FFFFFFF|FFFFFFF|FFFFFFF|FFFFFFF|FFFFFFF +; -; order matters for the following group -maskindex = $0A ; [byte][codegen] -stage = $0B ; [byte][codegen] -m_dst = $0C ; [word][codegen] -o_dst = $0E ; [word][codegen] -BoxStages = $10 ; [$30 bytes][must be at $10] +src = $00 ; [word][must be at $00] used by drawing routines +dst = $02 ; [word] used by drawing routines +box = $04 ; [byte] counter in main loop +any = $05 ; [byte] counter in main loop +rowcount = $06 ; [byte] used by drawing routines +alwaysFF = $0F ; [byte] used to set V flag +BoxStages = $10 ; [$30 bytes] current stage for each box +hgrhi = $40 ; [$C0 bytes] HGR base addresses +hgrlo = $300 ; [$C0 bytes] HGR base addresses +BoxesX = $200 ; [$30 bytes] starting row for each box +BoxesY = $230 ; [$30 bytes] starting byte offset for each box -hgrhi = $40 ; [$C0 bytes] -hgrlo = $300 ; [$C0 bytes] +; high bytes of drawing routines for each stage (actual routine will be page-aligned) +clear00 = $64 +clear01 = $65 +clear02 = $66 +clear03 = $67 +clear04 = $68 +clear05 = $69 +clear06 = $6A +clear07 = $6B +clear08 = $6C +clear09 = $6D +clear0A = $6E +clear0B = $6F +clear0C = $70 +clear0D = $71 +clear0E = $72 +clear0F = $73 +copy02 = $74 +copy03 = $75 +copy04 = $76 +copy05 = $77 +copy06 = $78 +copy07 = $79 +copy08 = $7A +copy09 = $7B +copy0A = $7C +copy0B = $7D +copy0C = $7E +copy0D = $7F +copy0E = $80 +copy0F = $81 +copy00 = $82 +copy01 = $83 -!macro RECALC_HIGH_ONLY { - lda hgrhi, x - sta dst+1 - eor #$60 - sta src+1 -} - -; recalculate HGR base addresses -; in: X = HGR row (00..BF) -; out: preserves X, Y -; clobbers A -!macro RECALC { - lda hgrlo, x - sta src - sta dst - +RECALC_HIGH_ONLY -} +; tokens for code generation +k_rts = 0 +k_inx_and_recalc = 1 +k_recalc = 2 +k_recalc_and_iny = 3 +k_recalc_high_only = 4 +k_clear_stage_01_init = 5 +k_copy_stage_01_init = 6 +k_stage0_precalc = 7 +k_stage0_maskcopy_and_inx = 8 +k_stage0_maskcopy = 9 +k_stage1_precalc = 10 +k_stage1_copy_and_inx = 11 +k_stage1_copy = 12 +k_stage_init = 13 +k_maskcopy_pre = 14 +k_maskcopy_post_and_iny = 15 +k_maskcopy_post = 16 +k_copy_and_iny = 17 +k_copy = 18 +k_dey2 = 19 +k_iny2 = 20 +k_middle_branches = 21 +k_outer_branches = 22 +k_edge_left_mask = 23 +k_edge_right_mask = 24 +k_left_mask = 25 +k_right_mask = 26 !source "src/fx/macros.a" ; actual code starts here + +; Generate |BoxesX| and |BoxesY| arrays +; BoxesX (starting row for each box) +; $00,$00,$00,$00,$00,$00,$00,$00 +; $20,$20,$20,$20,$20,$20,$20,$20 +; $40,$40,$40,$40,$40,$40,$40,$40 +; $60,$60,$60,$60,$60,$60,$60,$60 +; $80,$80,$80,$80,$80,$80,$80,$80 +; $A0,$A0,$A0,$A0,$A0,$A0,$A0,$A0 +; BoxesY (starting byte offset for each box) +; $00,$05,$0A,$0F,$14,$19,$1E,$23 +; $00,$05,$0A,$0F,$14,$19,$1E,$23 +; $00,$05,$0A,$0F,$14,$19,$1E,$23 +; $00,$05,$0A,$0F,$14,$19,$1E,$23 +; $00,$05,$0A,$0F,$14,$19,$1E,$23 +; $00,$05,$0A,$0F,$14,$19,$1E,$23 ldx #48 ldy #$A0 lda #$23 pha - tya - sta BoxesX-1,x + sta BoxesX-1, x pla - sta BoxesY-1,x + sta BoxesY-1, x sec sbc #5 bcs + @@ -64,101 +187,71 @@ hgrlo = $300 ; [$C0 bytes] bne - pla - ; X=0 + ; copy codegen data to zero page + ; X=0 here +- lda PIECES_COPY_START, x + sta $00, x + inx + bne - + + ; generate drawing routines for copy01, then copy00 + lda # $100) { + !error "out of room on zero page" +} -; -; Boxes are laid out in a grid, left-to-right, top-down: -; 0 1 2 3 4 5 6 7 -; 8 9 10 11 12 13 14 15 -; 16 17 18 19 20 21 22 23 -; 24 25 26 27 28 29 30 31 -; 32 33 34 35 36 37 38 39 -; 40 41 42 43 44 45 46 47 -; -; Each box is 35x32 pixels, so each row of each box is 5 consecutive -; bytes in memory once you calculate the HGR base address for that row. -; -BoxesX=EndStagesHi+256 -BoxesY=BoxesX+48 ; starting byte offset for each box - -CopyParams - ; must be immediately before BoxInitialStages so they get - ; copied into the right places in zero page - !byte 13 - !word $8D00 - !word $9B00 - -; The initial grid of stages for each box. -; Each box's stage is incremented on each iteration. -; Negative stages (80..FF) are no-ops. -; Positive stages (00..7F) are indexes into StagesHi array -; to find the actual drawing routine for this stage (if any). BoxInitialStages