Checkpoint after small code tidy-up

This commit is contained in:
Ben Bridle 2022-10-07 12:33:39 +13:00
parent d5372349a7
commit 1196ac2462
5 changed files with 78 additions and 77 deletions

View File

@ -158,4 +158,4 @@
( Invert all the bits in a number )
%INVERT { #ff EOR }
%INVERT* { #ffff EOR* }
%INVERT* { #ffff EOR* }

32
_print_macros.tal Normal file
View File

@ -0,0 +1,32 @@
( Print characters )
%PRINTF(\s) { ;print_space CALL }
%PRINTF(\n) { ;print_newline CALL }
( Print strings )
%PRINTF(%s) { ;print_string CALL }
%PRINTF(%s\s) { PRINTF(%s) PRINTF(\s) }
%PRINTF(%s\n) { PRINTF(%s) PRINTF(\n) }
( Print decimal numbers )
%PRINTF(%d) { ;print_byte_decimal CALL }
%PRINTF(%d\s) { PRINTF(%d) PRINTF(\s) }
%PRINTF(%d\n) { PRINTF(%d) PRINTF(\n) }
%PRINTF(%d*) { ;print_short_decimal CALL }
%PRINTF(%d*\s) { PRINTF(%d*) PRINTF(\s) }
%PRINTF(%d*\n) { PRINTF(%d*) PRINTF(\n) }
%PRINTF(%-d*) { ;print_short_decimal_signed CALL }
%PRINTF(%-d*\s) { PRINTF(%-d*) PRINTF(\s) }
%PRINTF(%-d*\n) { PRINTF(%-d*) PRINTF(\n) }
( Print binary numbers )
%PRINTF(%b) { ;print_byte_binary CALL }
%PRINTF(%b\s) { PRINTF(%b) PRINTF(\s) }
%PRINTF(%b\n) { PRINTF(%b) PRINTF(\n) }
( Print boolean values )
%PRINTF(%?) { ;print_bool CALL }
%PRINTF(%?\s) { PRINTF(%?) PRINTF(\s) }
%PRINTF(%?\n) { PRINTF(%?) PRINTF(\n) }
%PRINTF(%?*) { ;print_bool_short CALL }
%PRINTF(%?*\s) { PRINTF(%?) PRINTF(\s) }
%PRINTF(%?*\n) { PRINTF(%?) PRINTF(\n) }

View File

@ -1,31 +1,3 @@
%PRINTF(\s) { ;print_space CALL }
%PRINTF(\n) { ;print_newline CALL }
%PRINTF(%s) { ;print_string CALL }
%PRINTF(%s\s) { PRINTF(%s) PRINTF(\s) }
%PRINTF(%s\n) { PRINTF(%s) PRINTF(\n) }
%PRINTF(%d) { ;print_byte_decimal CALL }
%PRINTF(%d\s) { PRINTF(%d) PRINTF(\s) }
%PRINTF(%d\n) { PRINTF(%d) PRINTF(\n) }
%PRINTF(%d*) { ;print_short_decimal CALL }
%PRINTF(%d*\s) { PRINTF(%d*) PRINTF(\s) }
%PRINTF(%d*\n) { PRINTF(%d*) PRINTF(\n) }
%PRINTF(%-d*) { ;print_short_decimal_signed CALL }
%PRINTF(%-d*\s) { PRINTF(%-d*) PRINTF(\s) }
%PRINTF(%-d*\n) { PRINTF(%-d*) PRINTF(\n) }
%PRINTF(%b) { ;print_byte_binary CALL }
%PRINTF(%b\s) { PRINTF(%b) PRINTF(\s) }
%PRINTF(%b\n) { PRINTF(%b) PRINTF(\n) }
%PRINTF(%?) { ;print_bool CALL }
%PRINTF(%?\s) { PRINTF(%?) PRINTF(\s) }
%PRINTF(%?\n) { PRINTF(%?) PRINTF(\n) }
%PRINTF(%?*) { ;print_bool_short CALL }
%PRINTF(%?*\s) { PRINTF(%?) PRINTF(\s) }
%PRINTF(%?*\n) { PRINTF(%?) PRINTF(\n) }
@print_newline LIT <LINEFEED> /CONSOLE.WRITE! RETURN
@print_space LIT <SPACE> /CONSOLE.WRITE! RETURN
@ -41,7 +13,7 @@
( Print a single byte to the console in decimal )
@print_byte_decimal_signed ( byte -- )
DUP* IS_POSITIVE ,print_byte_decimal JCN
LIT "- /CONSOLE.WRITE! NEGATE
LIT "- /CONSOLE.WRITE! NEG
@print_byte_decimal ( byte -- )
;convert_byte_to_decimal_string CALL
PRINTF(%s) RETURN
@ -49,7 +21,7 @@
( Print a single short to the console in decimal )
@print_short_decimal_signed ( short* -- )
DUP* IS_POSITIVE* ,print_short_decimal JCN
LIT "- /CONSOLE.WRITE! NEGATE*
LIT "- /CONSOLE.WRITE! NEG*
@print_short_decimal ( short* -- )
;convert_short_to_decimal_string CALL
PRINTF(%s) RETURN

View File

@ -49,9 +49,10 @@
( Draw all UI elements )
@ui__draw_all /I.NUM_ELEMENTS? #00 ( -- )
&loop EQUk ,&end JCN ( total index )
EQUk ,&end JCN
&loop ( total index )
DUP ;ui__draw_single CALL ( total index )
INC ,&loop JMP ( total index )
INC GTHk ,&loop JCN ( total index )
&end POP* RETURN ( -- )
( Draw a single UI element by index )
@ -61,11 +62,11 @@
LDA* CALLRETURN ( active? )
( Call the callback for a single UI element by index, [ index -- ] )
@ui__press_go ;ui__callbacks/go ,__ui__call_callback JMP
@ui__press_inc #01 SWP ;ui__callbacks/change ,__ui__call_callback JMP
@ui__press_go ;ui__callbacks/go ,_ui__call_callback JMP
@ui__press_inc #01 SWP ;ui__callbacks/change ,_ui__call_callback JMP
@ui__press_dec #ff SWP ;ui__callbacks/change ( ... jump elided ... )
( Calculate the real address of a callback and call )
@__ui__call_callback ( index callback_block_start_addr* )
@_ui__call_callback ( index callback_block_start_addr* )
ROT TO_SHORT DOUBLE ADD* LDA* CALL ( real_callback_addr* )
;ui__redraw_controls CALLRETURN ( -- )
@ -74,19 +75,19 @@
and a callback address, followed by the number of pairs that were provided.
For example: [ #00 ;func0 #01 ;func1 #04 ;func4 #03 ]
Draw callbacks MUST consume the 1-byte 'active?' bool that is passed to them.
Change callbacks MUST consume the 1-byte 'delta' that is passed to them (is either -1 or 1).
Change callbacks MUST consume the 1-byte 'delta' that is passed to them, is either -1 or 1.
Go callbacks do not receive any data.
Signature for each 'register' subroutine is: [index callback*]+ count -- )
@ui__register_draw_callbacks ;ui__callbacks/draw ,__ui__register_callbacks JMP
@ui__register_change_callbacks ;ui__callbacks/change ,__ui__register_callbacks JMP
@ui__register_draw_callbacks ;ui__callbacks/draw ,_ui__register_callbacks JMP
@ui__register_change_callbacks ;ui__callbacks/change ,_ui__register_callbacks JMP
@ui__register_go_callbacks ;ui__callbacks/go ( ... jump elided ... )
@__ui__register_callbacks ( [index callback*]+ count block_addr* -- )
,&block_addr STR* ( [index callback*]+ count )
&loop ( [index callback*]+ count )
STH ROT DOUBLE TO_SHORT ( ... callback* offset* | count )
[ LIT* &block_addr $2 ] ADD* STA* ( ... | count )
STHr DEC DUP ,&loop JCN ( ... count )
POP RETURN ( -- )
@_ui__register_callbacks ( [index callback*]+ count block_addr* -- )
,&block_addr STR* #00 ( [index callback*]+ total i )
&loop
STH* ROT DOUBLE TO_SHORT ( ... callback* offset* | total i )
[ LIT* &block_addr $2 ] ADD* STA* ( ... | total i )
STHr* INC GTHk ,&loop JCN ( ... total i | )
POP* RETURN ( -- )
( Register a single screen zone for each of multiple UI elements )
@ui__register_zones ( [index left* top* width* height*]+ count -- )
@ -120,24 +121,27 @@
subroutine before declaring the UI for a new screen. )
@ui__initialise
@ui__clear
( Clear mouse button state, to prevent weird clicks when the new UI comes up )
#0000 DUP /I.MOUSE.PRESSED! /I.MOUSE.HELD! /I.MOUSE.RELEASED!
( Clear mouse button state, to prevent weird clicks when the new UI comes up )
#00 DUPk /I.MOUSE.PRESSED! /I.MOUSE.HELD! /I.MOUSE.RELEASED!
( Recalculate the center of the screen )
/SCREEN.WIDTH? HALVE* /I.CENTER.X! /SCREEN.HEIGHT? HALVE* /I.CENTER.Y!
/SCREEN.WIDTH? HALVE* /I.CENTER.X! /SCREEN.HEIGHT? HALVE* /I.CENTER.Y!
;clear_foreground CALL
;ui__callbacks ;ui__callbacks/end ;&null_callback ,__ui__clear_memory_region JSR
;ui__callbacks/draw ;ui__callbacks/end ;&pop_null_callback ,__ui__clear_memory_region JSR
;ui__zones ;ui__zones/end #0000 ,__ui__clear_memory_region JMP
&pop_null_callback POP &null_callback RETURN
( Fill a region of memory with a repeated value. Address includes `start_addr`, but excludes `end_addr`. )
@__ui__clear_memory_region ( start_addr* end_addr* value* -- )
STH* SWP* ( end* addr* | val* )
&loop ( end* addr* | val* )
EQUk* ,&end JCN ( end* addr* | val* )
STHkr* OVR* STA* ( addr* )
ADD2* ,&loop JMP ( end* addr* | val* )
( Clear all callbacks )
;ui__callbacks ;ui__callbacks/end ;null_callback ,_ui__clear_memory_region JSR
;ui__callbacks/draw ;ui__callbacks/end ;pop_null_callback ,_ui__clear_memory_region JSR
;ui__zones ;ui__zones/end #0000 ,_ui__clear_memory_region JMP
( Fill a region of memory with a repeated value. Address range includes start but excludes end. )
@_ui__clear_memory_region ( start_addr* end_addr* value* -- )
STH* SWP* EQUk ,&end JCN ( end* addr* | val* )
&loop
STHkr* OVR* STA* ( end* addr* | val* )
ADD2* GTHk ,&loop JCN ( end* addr* | val* )
&end POP* POP* POPr* RETURN
@pop_null_callback POP
@null_callback RETURN
( Mouse vector )
@ui__on_mouse ( -- )
( TODO: Add back in the mouse2 stuff )

View File

@ -61,12 +61,10 @@
#0080 /V.CANVAS.WIDTH! #0060 /V.CANVAS.HEIGHT! #01 /V.ACTIVE_TOOL!
( Seed default palettes for canvas and UI )
#1c8d /V.CANVAS.RED! #1619 /V.CANVAS.GREEN! #1010 /V.CANVAS.BLUE!
( TODO: Remove this line )
#1d44 /V.UI.RED! #2d68 /V.UI.GREEN! #397a /V.UI.BLUE!
#1d24 /V.UI.RED! #2d8a /V.UI.GREEN! #3946 /V.UI.BLUE!
;recenter_canvas CALL
;canvas_screen GOTO
;tool_screen GOTO
~_user_interface_framework.tal
@ -128,25 +126,20 @@
/V.ACTIVE_COLOUR? DUP ROT ( n n active? )
;draw_colour_swatch CALL ( n )
;load_merged_ui_palette CALLRETURN ( -- )
@colour_screen__draw__red ( active? -- )
#0024 /SCREEN.X! #0000 CENTER_DOWN!
/V.SCRATCH.RED? SWP ;draw_slider CALL
,reload_merged_colours JMP
@colour_screen__draw__green ( active? -- )
#0024 /SCREEN.X! #000b CENTER_DOWN!
/V.SCRATCH.GREEN? SWP ;draw_slider CALL
,reload_merged_colours JMP
@colour_screen__draw__blue ( active? -- )
#0024 /SCREEN.X! #0016 CENTER_DOWN!
/V.SCRATCH.BLUE? SWP ;draw_slider CALL
,reload_merged_colours JMP
@colour_screen__draw__red /V.SCRATCH.RED? #0000 ,colour_screen__draw__slider JMP
@colour_screen__draw__green /V.SCRATCH.GREEN? #000b ,colour_screen__draw__slider JMP
@colour_screen__draw__blue /V.SCRATCH.BLUE? #0016 ( ... jump elided ... )
@colour_screen__draw__slider ( active? value y_offset* )
CENTER_DOWN! #0024 /SCREEN.X!
SWP ;draw_slider CALL
/V.ACTIVE_COLOUR?
;load_merged_ui_palette CALLRETURN
@colour_screen__draw__sliders ( -- )
#00 DUPk
,colour_screen__draw__red JSR
,colour_screen__draw__green JSR
,colour_screen__draw__blue JMP
@reload_merged_colours ( -- )
/V.ACTIVE_COLOUR? ;load_merged_ui_palette CALLRETURN