parse frame output and calculate a width

This commit is contained in:
~d6 2024-08-25 23:51:17 -04:00
parent 75c62e88fb
commit d3a7f49540
1 changed files with 58 additions and 3 deletions

61
mp3.tal
View File

@ -81,12 +81,67 @@
( INC2k LDA LIT "T EQU ?on-tag ) ( INC2k LDA LIT "T EQU ?on-tag )
!printerr !printerr
( === START NEW CODE === )
( e.g. "@F 184 8713 4.81 227.60" ) ( e.g. "@F 184 8713 4.81 227.60" )
( seen when playing ) ( seen when playing )
( the fields here are: ) ( the fields here are: )
( @F <curr-frame> <total-frames> <curr-secs> <total-secs> ) ( @F <curr-frame> <total-frames> <curr-secs> <remaining-secs> )
@on-frame ( buf* -> ) ( )
POP2 JMP2r ( debugging output on stderr is: <curr-time> <rem-time> <width> )
@on-frame ( buf0* -> )
#0003 ADD2 ( buf1* ; skip "@F " )
#20 find-next INC2 ( buf2* ; skip curr frame )
#20 find-next INC2 ( buf3* ; skip next frame )
parse-dec STH2 INC2 ( buf4* [curr*] ; parse curr time )
LDAk LIT "5 LTH ?{ INC2r } ( buf4* [curr*] ; maybe round curr )
#20 find-next INC2 ( buf5* [curr*] ; skip fractional part )
parse-dec STH2 INC2 ( buf4* [curr* rem*] ; parse total time )
LDAk LIT "5 LTH ?{ INC2r } ( buf4* [curr* rem*] ; maybe round rem )
POP2 STH2r STH2r SWP2 ( curr* rem* )
OVR2 emit #2019 DEO ( curr* rem* ; print curr )
DUP2 emit #2019 DEO ( curr* rem* ; print rem )
OVR2 ADD2 SWP2 ( total* curr* )
calc-width emit #0a19 DEO ( width* )
JMP2r ( width* )
( emit a short in hexadecimal notation. )
@emit ( n* -> )
SWP /byte
&byte DUP #04 SFT /hex #0f AND ( >> )
&hex #30 ADD DUP #39 GTH #27 MUL ADD .Console/error DEO JMP2r
( returns value between 0000 and 00d0 )
( )
( the basic idea is that we shift both values left until )
( the total is small enough that it can be multiplied by )
( 0xd0, i.e. 208. we take some care to round correctly, )
( which helps give a smoother transition between values. )
@calc-width ( total* curr* -> width* )
STH2 ( total* [curr*] )
DUP2 #013c LTH2 ?&ready
&scale DUP2 #0277 LTH2 ?&almost #01 SFT2 LITr 01 SFT2r !&scale
&almost INC2 #01 SFT2 INC2r LITr 01 SFT2r
&ready LIT2r 00d0 MUL2r STH2r SWP2 DIV2 JMP2r
( find the next occurrence of a byte in the given string. )
( )
( returns the position of the character found. )
@find-next ( buf* c^ -> buf+i* )
STH &loop LDAk STHkr EQU ?{ INC2 !&loop } POPr JMP2r
( parse a decimal number as a short )
( )
( returns an updated buffer position and the parsed short )
@parse-dec ( buf* -> buf+i* x* )
LIT2r 000a LIT2r 0000 ( buf* [10* acc*] )
&loop LDAk LIT "0 SUB ( buf+i* n^ [10* acc*] )
DUP #09 GTH ?&done ( buf+i* n^ [10* acc*] )
OVR2r MUL2r #00 SWP ( buf+i* n* [10* 10acc*] )
STH2 ADD2r INC2 !&loop ( buf+i+1* [10* 10acc+n*] )
&done POP STH2r POP2r JMP2r ( buf+i* acc* )
( === END NEW CODE === )
( e.g. "@H HELP/H: command listing (LONG/SHORT forms), command case insensitve" ) ( e.g. "@H HELP/H: command listing (LONG/SHORT forms), command case insensitve" )
( seen in response to the "help" command ) ( seen in response to the "help" command )