;license:MIT ;(c) 2021 by 4am & qkumba ; !cpu 6502 !to "build/FX.INDEXED/SHR.80BOXES",plain *=$A000 ; The SHR screen in 320x200 mode is separated into 80 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 48 49 ; 50 51 52 53 54 55 56 57 58 59 ; 60 61 62 63 64 65 66 67 68 69 ; 70 71 72 73 74 75 76 77 78 79 ; ; Each box is 32x25 pixels, so each row of each box is 16 consecutive ; bytes in memory (2 pixels per byte) once you calculate the SHR base ; address for that row. ; ; |BoxStages| defines the initial grid of stages for each box. ; Each stage is used as an index into the |StagesHi| array ; to find the drawing routine for that stage (if any). ; Each box's stage is incremented after each iteration through the main loop. ; When the main loop iterates through all 80 boxes without drawing anything, ; the program exits. ; ; There are 7 clear routines that set certain pixels to color 0 (usually black) ; labeled clear00..clear06. clear00 clears the inner-most box, and ; clear06 clears the outermost box (see diagram). ; There are 7 copy routines that copy certain pixels from the source ; image in mainmem to the destination image in auxmem, labeled copy00..copy06. ; ; row| pixels ; ---+.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- ; 00 |66666666666666666666666666666666 ; 01 |66666666666666666666666666666666 ; 02 |66555555555555555555555555555566 ; 03 |66555555555555555555555555555566 ; 04 |66554444444444444444444444445566 ; 05 |66554444444444444444444444445566 ; 06 |66554433333333333333333333445566 ; 07 |66554433333333333333333333445566 ; 08 |66554433222222222222222233445566 ; 09 |66554433222222222222222233445566 ; 10 |66554433221111111111112233445566 ; 11 |66554433221111111111112233445566 ; 12 |66554433221100000000112233445566 ; 13 |66554433221111111111112233445566 ; 14 |66554433221111111111112233445566 ; 15 |66554433222222222222222233445566 ; 16 |66554433222222222222222233445566 ; 17 |66554433333333333333333333445566 ; 18 |66554433333333333333333333445566 ; 19 |66554444444444444444444444445566 ; 20 |66554444444444444444444444445566 ; 21 |66555555555555555555555555555566 ; 22 |66555555555555555555555555555566 ; 23 |66666666666666666666666666666666 ; 24 |66666666666666666666666666666666 ; ; Each routine manipulates pixels in horizontal pairs, meaning we can copy ; bytes without having to worry about masking high and low nibbles. ; Each routine except copy00 is similar, defined by 4 parameters: ; - top row (absolute row, i.e. 00..C7) ; - bottom row (should probably use the first of the two, also absolute) ; - left (should probably be in bytes, also absolute) ; - right (should probably be in bytes, also absolute) ; ; On [top row] and [top row + 1], copy bytes from [left offset] to [right offset] ; While [current row] < [bottom row], draw 1 byte at [left offset] and 1 byte at [right offset] ; On [bottom row] and [bottom row + 1], copy bytes from [left offset] to [right offset] shrlo = $201 ; [$C8 bytes] shrhi = $301 ; [$C8 bytes] !source "src/fx/macros.a" !source "src/fx/fx.shr.common.a" ldx #0 - ldy start, x sty $00, x sta EndStagesHi, x inx bne - stx seta+1 stx sub1+1 ldx #-25 stx sub2+1 --- ldx #8 seta lda #0 -- pha ldy #10-1 - sta (BoxesY != >BoxesX) { !error "Boxes array crosses a page" } !align $FF,0,0 ; align to page copy01 +INIT_DRAW 10, 1, 5 bit copy00 !byte >copy01 !byte >copy02 !byte >copy03 !byte >copy04 !byte >copy05 !byte >copy06 EndStagesHi