Difference between revisions of "Homebrew:Test Controls"
From veswiki
Line 10: | Line 10: | ||
Binary file and source code download:<br> | Binary file and source code download:<br> | ||
− | [ | + | [https://channelf.se/veswiki/images/a/a9/Test_controls.zip Test Controls binary and source (zip 7kB)] |
Latest revision as of 15:17, 12 April 2022
Running Test Controls.
Program to test the buttons and controllers of your Channel F console.
Binary file and source code download:
Test Controls binary and source (zip 7kB)
Code:
; Input Test program ; written by ; Fredric Blåholtz ; 2007 ; ; dasm game.asm -f3 -ogame.bin to compile processor f8 ;=========================================================================== ; Colors ;=========================================================================== red = $40 blue = $80 green = $00 bkg = $C0 clear = $FF ;=========================================================================== ; Configuration ;=========================================================================== game_size = 2 ; game size in kilobytes ;=========================================================================== ; Program Entry ;=========================================================================== ;--------------------------------------------------------------------------- ; Cartridge Initalization ;--------------------------------------------------------------------------- org $800 .byte $55, $FB ; valid cart indicator, unused byte li blue lr 2, A li $ff lr 3, A lr 4, A li 104 lr 5, A li 60 lr 6, A ;---------------; ; fillscreen Function ; ;---------------; ; this function blits a graphic based on parameters set in r1-r6, ; and the graphic data pointed to by DC0, onto the screen ; ; originally from cart 26, modified and annotated ; uses r1-r9, K, Q ; ; r1 = color 1 (off) ; r2 = color 2 (on) ; r3 = x position ; r4 = y position ; r5 = width ; r6 = height (and vertical counter) ; ; r7 = horizontal counter ; r8 = graphics byte ; r9 = bit counter ; ; DC = pointer to graphics fillscreen: ; adjust the x coordinate lis 4 as 3 lr 3, A ; adjust the y coordinate lis 4 as 4 lr 4, A lis 1 lr 9, A ; load #1 into r9 so it'll be reset when we start lr A, 4 ; load the y offset com ; invert it fillscreen.row: outs 5 ; load accumulator into port 5 (row) ; check vertical counter ds 6 ; decrease r6 (vertical counter) bnc fillscreen.exit ; if it rolls over exit ; load the width into the horizontal counter lr A, 5 lr 7, A lr A, 3 ; load the x position com ; complement it fillscreen.column: outs 4 ; use the accumulator as our initial column ; check to see if this byte is finished ds 9 ; decrease r9 (bit counter) bnz fillscreen.drawBit ; if we aren't done with this byte, branch fillscreen.getByte: ; get the next graphics byte and set related registers lis 8 lr 9, A ; load #8 into r9 (bit counter) fillscreen.drawBit: ; check color to use lr A, 2 ; load color 1 bc fillscreen.savePixel ; if this bit is on, draw the color lr A, 1 ; load color 2 fillscreen.savePixel: inc bc fillscreen.checkColumn ; branch if the color is "clear" outs 1 ; output A in p1 (color) fillscreen.transferData: ; transfer the pixel data li $60 outs 0 li $40 outs 0 ; and delay a little bit lis 2 fillscreen.savePixelDelay: ai $ff bnz fillscreen.savePixelDelay fillscreen.checkColumn: ds 7 ; decrease r7 (horizontal counter) bz fillscreen.checkRow ; if it's 0, branch ins 4 ; get p4 (column) ai $ff ; add 1 (complemented) br fillscreen.column ; branch fillscreen.checkRow: ins 5 ; get p5 (row) ai $ff ; add 1 (complemented) br fillscreen.row ; branch fillscreen.exit: ; set screen to blue, grey background dci gfx.palette.parameters pi blitGraphic ; plot text dci text_buttons lis 7 ; store word length in r10 lr 10, A li clear ; 0 color lr 1, A li bkg ; 1 color lr 2, A li 30 ; x lr 3, A lr 11, A ; backup text_buttons_get_char: li 34 ; y lr 4, A lis 8 ; width lr 5, A lis 5 ; height lr 6, A li 64 com inc ; -64 in A am lr 7, A xdc dci bitmaps text_buttons_loop: bz text_buttons_blit_char lis 5 adc ds 7 br text_buttons_loop text_buttons_blit_char: pi blit ; plots character xdc ds 10 bz text_buttons_end li 6 ; add offset to blit x-register as 11 lr 11, A lr 3, A br text_buttons_get_char text_buttons_end: dci text_right li 87 ; x lr 3, A text_right_get_char: li 32 ; y lr 4, A lis 8 ; width lr 5, A lis 5 ; height lr 6, A li 64 com inc ; -64 in A am lr 7, A xdc dci bitmaps text_right_loop: bz text_right_blit_char lis 5 adc ds 7 br text_right_loop text_right_blit_char: pi blit ; plots character text_right_end: dci text_left li 9 ; x lr 3, A text_left_get_char: li 32 ; y lr 4, A lis 8 ; width lr 5, A lis 5 ; height lr 6, A li 64 com inc ; -64 in A am lr 7, A xdc dci bitmaps text_left_loop: bz text_left_blit_char lis 5 adc ds 7 br text_left_loop text_left_blit_char: pi blit ; plots character text_left_end: dci text_control lis 13 ; store word length in r10 lr 10, A li 12 ; x lr 3, A lr 11, A ; backup text_control_get_char: li 3 ; y lr 4, A lis 8 ; width lr 5, A lis 5 ; height lr 6, A li 64 com inc ; -64 in A am lr 7, A xdc dci bitmaps text_control_loop: bz text_control_blit_char lis 5 adc ds 7 br text_control_loop text_control_blit_char: pi blit ; plots character xdc ds 10 bz text_control_end li 6 ; add offset to blit x-register as 11 lr 11, A lr 3, A br text_control_get_char text_control_end: dci bitmap_numbers lis 4 ; store word length in r10 lr 10, A li 23 ; x lr 3, A lr 11, A ; backup text_numbers_get_char: li 47 ; y lr 4, A lis 8 ; width lr 5, A lis 5 ; height lr 6, A text_numbers_blit_char: pi blit ; plots character ds 10 bz text_numbers_end li 16 ; add offset to blit x-register as 11 lr 11, A lr 3, A br text_numbers_get_char text_numbers_end: ; continously draw any I/O green, mark errors with red ; check right controller big_loop: clr outs 0 outs 1 ; check right hand controller ins 1 com ; re-invert controller data lr 10, A ; back-up in r10 dci gfx.block4.parameters ; r.hc right lr A, 10 ni %00000001 bnz rhcright1 pi blitGraphic br rhcleft rhcright1: pi greenGraphic rhcleft: dci gfx.block3.parameters ; r.hc left lr A, 10 ni %00000010 bnz rhcleft1 pi blitGraphic br rhcbackward rhcleft1: pi greenGraphic rhcbackward: dci gfx.block8.parameters ; r.hc backward lr A, 10 ni %00000100 bnz rhcbackward1 pi blitGraphic br rhcforward rhcbackward1: pi greenGraphic rhcforward: dci gfx.block7.parameters ; r.hc forward lr A, 10 ni %00001000 bnz rhcforward1 pi blitGraphic br rhcccw rhcforward1: pi greenGraphic rhcccw: dci gfx.cclockwise2.parameters ; r.hc ccw lr A, 10 ni %00010000 bnz rhcccw1 pi blitGraphic br rhccw rhcccw1: pi greenGraphic rhccw: dci gfx.clockwise2.parameters ; r.hc cw lr A, 10 ni %00100000 bnz rhccw1 pi blitGraphic br rhcup rhccw1: pi greenGraphic rhcup: dci gfx.up2.parameters ; r.hc up lr A, 10 ni %01000000 bnz rhcup1 pi blitGraphic br rhcdown rhcup1: pi greenGraphic rhcdown: dci gfx.down2.parameters ; r.hc down lr A, 10 ni %10000000 bnz rhcdown1 pi blitGraphic br errorcheckright rhcdown1: pi greenGraphic errorcheckright: ; error check lr A, 10 ni %00000011 ci %00000011 bnz rhcfandb dci gfx.block4.parameters ; r.hc right pi redGraphic dci gfx.block3.parameters ; r.hc left pi redGraphic rhcfandb: lr A, 10 ni %00001100 ci %00001100 bnz rhccwandccw dci gfx.block8.parameters ; r.hc backward pi redGraphic dci gfx.block7.parameters ; r.hc forward pi redGraphic rhccwandccw: lr A, 10 ni %00110000 ci %00110000 bnz rhcupanddown dci gfx.cclockwise2.parameters ; r.hc ccw pi redGraphic dci gfx.clockwise2.parameters ; r.hc cw pi redGraphic rhcupanddown: lr A, 10 ni %11000000 ci %11000000 bnz thelefthandcontroller dci gfx.up2.parameters ; r.hc up pi redGraphic dci gfx.down2.parameters ; r.hc down pi redGraphic ; check the left controller thelefthandcontroller: clr outs 0 outs 4 ; check left hand controller ins 4 com lr 10, A ; backup in r10 dci gfx.block2.parameters ; l.hc right lr A, 10 ni %00000001 bnz lhcright1 pi blitGraphic br lhcleft lhcright1: pi greenGraphic lhcleft: dci gfx.block.parameters ; l.hc left lr A, 10 ni %00000010 bnz lhcleft1 pi blitGraphic br lhcbackward lhcleft1: pi greenGraphic lhcbackward: dci gfx.block6.parameters ; l.hc backward lr A, 10 ni %00000100 bnz lhcbackward1 pi blitGraphic br lhcforward lhcbackward1: pi greenGraphic lhcforward: dci gfx.block5.parameters ; l.hc forward lr A, 10 ni %00001000 bnz lhcforward1 pi blitGraphic br lhcccw lhcforward1: pi greenGraphic lhcccw: dci gfx.cclockwise.parameters ; l.hc ccw lr A, 10 ni %00010000 bnz lhcccw1 pi blitGraphic br lhccw lhcccw1: pi greenGraphic lhccw: dci gfx.clockwise.parameters ; l.hc cw lr A, 10 ni %00100000 bnz lhccw1 pi blitGraphic br lhcup lhccw1: pi greenGraphic lhcup: dci gfx.up.parameters ; l.hc up lr A, 10 ni %01000000 bnz lhcup1 pi blitGraphic br lhcdown lhcup1: pi greenGraphic lhcdown: dci gfx.down.parameters ; l.hc down lr A, 10 ni %10000000 bnz lhcdown1 pi blitGraphic br errorcheckleft lhcdown1: pi greenGraphic errorcheckleft: ; error check lr A, 10 ni %00000011 ci %00000011 bnz lhcfandb dci gfx.block2.parameters ; l.hc right pi redGraphic dci gfx.block.parameters ; l.hc left pi redGraphic lhcfandb: lr A, 10 ni %00001100 ci %00001100 bnz lhccwandccw dci gfx.block6.parameters ; l.hc backward pi redGraphic dci gfx.block5.parameters ; l.hc forward pi redGraphic lhccwandccw: lr A, 10 ni %00110000 ci %00110000 bnz lhcupanddown dci gfx.cclockwise.parameters ; l.hc ccw pi redGraphic dci gfx.clockwise.parameters ; l.hc cw pi redGraphic lhcupanddown: lr A, 10 ni %11000000 ci %11000000 bnz thebuttons dci gfx.up.parameters ; l.hc up pi redGraphic dci gfx.down.parameters ; l.hc down pi redGraphic thebuttons: ins 0 ; get button input from port 0 com ; invert lr 10, A dci gfx.button1.parameters lr A, 10 ni %00000001 bnz button1on pi blitGraphic br button2 button1on: pi greenGraphic button2: dci gfx.button2.parameters lr A, 10 ni %00000010 bnz button2on pi blitGraphic br button3 button2on: pi greenGraphic button3: dci gfx.button3.parameters lr A, 10 ni %00000100 bnz button3on pi blitGraphic br button4 button3on: pi greenGraphic button4: dci gfx.button4.parameters lr A, 10 ni %00001000 bnz button4on pi blitGraphic br end_of_IO_test button4on: pi greenGraphic end_of_IO_test: jmp big_loop ;=========================================================================== ; Data ;=========================================================================== ;--------------------------------------------------------------------------- gfx.palette.parameters: .byte bkg ; color 1 .byte green ; color 2 .byte 121 ; x position .byte 0 ; y position .byte 2 ; width .byte 58 ; height .word gfx.palette.data ; address for the graphics gfx.palette.data: .byte %01010111, %11111111, %01010101, %01010101, %01010101, %01010101, %01010101 .byte %01010101, %11111111, %11111101, %01010101, %01010111, %11111111, %01010101 .byte %01010101 ;--------------------------------------------------------------------------- gfx.block.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 10 ; x position .byte 20 ; y position .byte 7 ; width .byte 3 ; height .word gfx.block.data ; address for the graphics gfx.block.data: .byte $ff,$ff,$ff gfx.block2.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 31 ; x position .byte 20 ; y position .byte 7 ; width .byte 3 ; height .word gfx.block.data ; address for the graphics gfx.block3.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 63 ; x position .byte 20 ; y position .byte 7 ; width .byte 3 ; height .word gfx.block.data ; address for the graphics gfx.block4.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 84 ; x position .byte 20 ; y position .byte 7 ; width .byte 3 ; height .word gfx.block.data ; address for the graphics gfx.block5.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 22 ; x position .byte 11 ; y position .byte 4 ; width .byte 5 ; height .word gfx.block5.data ; address for the graphics gfx.block5.data: .byte $ff,$ff,$ff,$ff gfx.block6.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 22 ; x position .byte 27 ; y position .byte 4 ; width .byte 5 ; height .word gfx.block5.data ; address for the graphics gfx.block7.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 75 ; x position .byte 11 ; y position .byte 4 ; width .byte 5 ; height .word gfx.block5.data ; address for the graphics gfx.block8.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 75 ; x position .byte 27 ; y position .byte 4 ; width .byte 5 ; height .word gfx.block5.data ; address for the graphics gfx.clockwise.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 28 ; x position .byte 11 ; y position .byte 8 ; width .byte 6 ; height .word gfx.clockwise.data ; address for the graphics gfx.clockwise.data: .byte %01000000,%11110000,%01111000,%00011101,%00000111,%00011111 gfx.clockwise2.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 81 ; x position .byte 11 ; y position .byte 8 ; width .byte 6 ; height .word gfx.clockwise.data ; address for the graphics gfx.cclockwise.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 12 ; x position .byte 11 ; y position .byte 8 ; width .byte 6 ; height .word gfx.cclockwise.data ; address for the graphics gfx.cclockwise.data: .byte %00000010,%00001111,%00011110,%10111000,%11100000,%11111000 gfx.cclockwise2.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 65 ; x position .byte 11 ; y position .byte 8 ; width .byte 6 ; height .word gfx.cclockwise.data ; address for the graphics gfx.up.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 22 ; x position .byte 20 ; y position .byte 4 ; width .byte 3 ; height .word gfx.up.data ; address for the graphics gfx.up.data: .byte %01101111,%01100000 gfx.up2.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 75 ; x position .byte 20 ; y position .byte 4 ; width .byte 3 ; height .word gfx.up.data ; address for the graphics gfx.down.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 19 ; x position .byte 18 ; y position .byte 10 ; width .byte 7 ; height .word gfx.down.data ; address for the graphics gfx.down.data: .byte %00011110,%00011000,%01100100,%00001011,%00000011 .byte %01000000,%10011000,%01100001,%11100000 ;0001111000 ;0110000110 ;0100000010 ;1100000011 ;0100000010 ;0110000110 ;0001111000 gfx.down2.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 72 ; x position .byte 18 ; y position .byte 10 ; width .byte 7 ; height .word gfx.down.data ; address for the graphics gfx.button1.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 21 ; x position .byte 40 ; y position .byte 8 ; width .byte 6 ; height .word gfx.button1.data ; address for the graphics gfx.button1.data: .byte $ff,$ff,$ff,$ff,$ff,$ff gfx.button2.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 37 ; x position .byte 40 ; y position .byte 8 ; width .byte 6 ; height .word gfx.button1.data ; address for the graphics gfx.button3.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 53 ; x position .byte 40 ; y position .byte 8 ; width .byte 6 ; height .word gfx.button1.data ; address for the graphics gfx.button4.parameters: .byte clear ; color 1 .byte bkg ; color 2 .byte 70 ; x position .byte 40 ; y position .byte 8 ; width .byte 6 ; height .word gfx.button1.data ; address for the graphics text_buttons: .byte "BUTTONS" text_left: .byte "L" text_right: .byte "R" text_control: .byte "TEST@CONTROLS" bitmaps: ;5x5 character bitmaps offset db $00,$00,$00,$00,$00 ; space db $F8,$88,$F8,$88,$88 ; "A" db $F8,$48,$78,$48,$F8 ; "B" db $F8,$80,$80,$80,$F8 ; "C" db $F8,$48,$48,$48,$F8 ; "D" db $F8,$80,$E0,$80,$F8 ; "E" db $F8,$80,$E0,$80,$80 ; "F" db $F8,$80,$98,$88,$F8 ; "G" db $88,$88,$F8,$88,$88 ; "H" db $F8,$20,$20,$20,$F8 ; "I" db $F8,$20,$20,$A0,$E0 ; "J" db $90,$A0,$C0,$A0,$90 ; "K" db $80,$80,$80,$80,$F8 ; "L" db $88,$D8,$A8,$88,$88 ; "M" db $88,$C8,$A8,$98,$88 ; "N" db $F8,$88,$88,$88,$F8 ; "O" db $F8,$88,$F8,$80,$80 ; "P" db $F8,$88,$88,$90,$E8 ; "Q" db $F8,$88,$F8,$90,$88 ; "R" db $F8,$80,$F8,$08,$F8 ; "S" db $F8,$20,$20,$20,$20 ; "T" db $88,$88,$88,$88,$F8 ; "U" db $88,$88,$88,$50,$20 ; "V" db $88,$88,$A8,$D8,$88 ; "W" db $88,$50,$20,$50,$88 ; "X" db $88,$88,$F8,$20,$20 ; "Y" db $F8,$10,$20,$40,$F8 ; "Z" bitmap_numbers: db $20,$60,$20,$20,$70 ; "1" db $F8,$08,$F8,$80,$F8 ; "2" db $F8,$08,$38,$08,$F8 ; "3" db $88,$88,$F8,$08,$08 ; "4" ;=========================================================================== ; Includes ;=========================================================================== include "drawing.inc" ;=========================================================================== ; Signature ;=========================================================================== ; signature org [$800 + [game_size * $400] - $10] signature: .byte "·Blåholtz· 2007"
Code for drawing.inc:
;===================; ; Drawing Functions ; ;===================; ;---------------; ; Plot Function ; ;---------------; ; plot out a single point on the screen ; uses three registers as "arguments" ; r1 = color ; r2 = x (to screen) (0-101) ; r3 = y (to screen) (0-57) plot: ; set the color using r1 lr A, 1 outs 1 ; set the column using r2 lis 4 as 2 ; fix the x coordinate com outs 4 ; set the row using r3 lis 4 as 3 ; fix the y coordinate com outs 5 ; transfer data to the screen memory lis $6 sl 4 outs 0 lis $5 sl 4 outs 0 ; delay until it's fully updated lis 6 plot.delay: ai $ff bnz plot.delay pop ; return from the subroutine ; takes graphic parameters from ROM, stores them in r1-r6, ; changes the DC and calls the blit function with the parameters blitGraphic: ; load six bytes from the parameters into r0-r5 lisu 0 lisl 1 blitGraphic.getParams: lm lr I, A ; store byte and decrease ISAR br7 blitGraphic.getParams ; not finished with the registers, loop ; load the graphics address lm lr Qu, A ; into Q lm lr Ql, A lr DC, Q ; load it into the DC ; call the blit function jmp blit ;---------------; ; Blit Function ; ;---------------; ; this function blits a graphic based on parameters set in r1-r6, ; and the graphic data pointed to by DC0, onto the screen ; ; originally from cart 26, modified and annotated ; uses r1-r9, K, Q ; ; r1 = color 1 (off) ; r2 = color 2 (on) ; r3 = x position ; r4 = y position ; r5 = width ; r6 = height (and vertical counter) ; ; r7 = horizontal counter ; r8 = graphics byte ; r9 = bit counter ; ; DC = pointer to graphics blit: ; adjust the x coordinate lis 4 as 3 lr 3, A ; adjust the y coordinate lis 4 as 4 lr 4, A lis 1 lr 9, A ; load #1 into r9 so it'll be reset when we start lr A, 4 ; load the y offset com ; invert it blit.row: outs 5 ; load accumulator into port 5 (row) ; check vertical counter ds 6 ; decrease r6 (vertical counter) bnc blit.exit ; if it rolls over exit ; load the width into the horizontal counter lr A, 5 lr 7, A lr A, 3 ; load the x position com ; complement it blit.column: outs 4 ; use the accumulator as our initial column ; check to see if this byte is finished ds 9 ; decrease r9 (bit counter) bnz blit.drawBit ; if we aren't done with this byte, branch blit.getByte: ; get the next graphics byte and set related registers lis 8 lr 9, A ; load #8 into r9 (bit counter) lm lr 8, A ; load a graphics byte into r8 blit.drawBit: ; shift graphics byte lr A, 8 ; load r8 (graphics byte) as 8 ; shift left one (with carry) lr 8, A ; save it ; check color to use lr A, 2 ; load color 1 bc blit.savePixel ; if this bit is on, draw the color lr A, 1 ; load color 2 blit.savePixel: inc bc blit.checkColumn ; branch if the color is "clear" outs 1 ; output A in p1 (color) blit.transferData: ; transfer the pixel data li $60 outs 0 li $40 outs 0 ; and delay a little bit ; ============================================================================= ; ; The original delay was 35.5 cycles: ; ; Acumulator was $C0 ; ;blit.savePixelDelay: ; ai $60 ; bnz blit.savePixelDelay ; small delay ; ; ; 9 cycle delay works on old NTSC system ; 8 is to little. (tested by e5frog) ; ; ; jmp blit.savePixelDelay ; 5.5 cycles ;blit.savePixelDelay: ; br blit.checkColumn ; 3.5 cycles ; ; ; Old PAL system works faster and requires longer delay ; 12.5 cycles is sufficient, 12 is too little lis 2 blit.savePixelDelay: ai $ff bnz blit.savePixelDelay blit.checkColumn: ds 7 ; decrease r7 (horizontal counter) bz blit.checkRow ; if it's 0, branch ins 4 ; get p4 (column) ai $ff ; add 1 (complemented) br blit.column ; branch blit.checkRow: ins 5 ; get p5 (row) ai $ff ; add 1 (complemented) br blit.row ; branch blit.exit: ; return from the subroutine pop greenGraphic: ; load six bytes from the parameters into r0-r5 lisu 0 lisl 1 lm lr I, A ; store byte and decrease ISAR lm li green lr I, A br blitGraphic.getParams redGraphic: ; load six bytes from the parameters into r0-r5 lisu 0 lisl 1 lm lr I, A ; store byte and decrease ISAR lm li red lr I, A br blitGraphic.getParams