I'm working on modernizing Rosetta Code's infrastructure. Starting with communications. Please accept this time-limited open invite to RC's Slack.. --Michael Mol (talk) 20:59, 30 May 2020 (UTC)

Category talk:ZX Spectrum Basic

From Rosetta Code

Embedded machine code[edit]

I'm presuming it's a no-no, but where are we on the use of USR functions to run machine code routines? (And, for that matter, direct memory addressing via PEEK and POKE; I'm looking at screen attributes in particular.) I've got a couple of projects which use machine code for speed and ease of handling of bitwise operations (which are non-existent natively in Sinclair Basic - it'd be replicable but agonisingly slow) - it's mainly for visual flavour and can be easily REMmed out, but a ruling would be handy. I've seen it done here with a couple of ZX81 demos.

(e.g. the below is techincally valid ZX Spectrum Basic, but it's a stretch to say that the functionality is truly BASIC...)

10 CLEAR 64999
20 RESTORE 1000
30 LET h$="0123456789ABCDEF"
40 LET o=65000
50 READ a$
60 IF a$="eof" THEN GO TO 190
70 FOR x=1 TO 8
80 LET n=0
90 LET t=x*2
100 LET s=t-1
110 FOR m=1 TO 16
120 IF h$(m)=a$(s) THEN LET n=n+16*(m-1)
130 IF h$(m)=a$(t) THEN LET n=n+m-1
140 NEXT m
150 POKE o,n
160 LET o=o+1
170 NEXT x
180 GO TO 50
190 RANDOMIZE USR 65018
200 STOP
 
1000 DATA "66697A7A62757A7A"
1010 DATA "0D66697A7A0D2020"
1020 DATA "200D010100C579D6"
1030 DATA "0FCA0AFED2FFFDC3"
1040 DATA "13FE01090011E8FD"
1050 DATA "C398FEC1C579D605"
1060 DATA "CA21FED216FEC32A"
1070 DATA "FE01050011ECFDC3"
1080 DATA "98FEC1C579D603CA"
1090 DATA "38FED22DFEC341FE"
1100 DATA "01050011F1FDC398"
1110 DATA "FEDD21F6FD2E20DD"
1120 DATA "7500DD7501DD7502"
1130 DATA "21F6FDC1C579D664"
1140 DATA "C25EFE363123C1C5"
1150 DATA "790600FE64DA6DFE"
1160 DATA "D664C363FEFE0ADA"
1170 DATA "7BFECA7BFED60A04"
1180 DATA "C36DFE5F78A7CA84"
1190 DATA "FEC38AFE7DFEF6CA"
1200 DATA "8EFEC63077237BC6"
1210 DATA "307701040011F6FD"
1220 DATA "218C5C3605C5D53E"
1230 DATA "02DDE5CD0116DDE1"
1240 DATA "D1C1CD3C20C10379"
1250 DATA "FE65C2FDFDC90000"
1260 DATA "eof"
- Kinitawowi (talk) 23:53, 8 March 2020 (UTC)