BASIC: byte value to bits...

Hardware Hacking, Programming and Game Solutions/Cheats
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: BASIC: byte value to bits...

Post by jedie »

Now i make it in this form:

Code: Select all

223 T = CC
224 B7$=".":IF T AND 128 THEN B7$="E"
225 B6$=".":IF T AND 64 THEN B6$="F"
226 B5$=".":IF T AND 32 THEN B5$="H"
227 B4$=".":IF T AND 16 THEN B4$="I"
228 B3$=".":IF T AND 8 THEN B3$="N"
229 B2$=".":IF T AND 4 THEN B2$="Z"
230 B1$=".":IF T AND 2 THEN B1$="V"
231 B0$=".":IF T AND 1 THEN B1$="C"
232 B7$;B6$;B5$;B4$;B3$;B2$;B1$;B0$
It will be result into this: viewtopic.php?f=8&t=4402&p=9720#p9720
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: BASIC: byte value to bits...

Post by JeeK »

I'm obsessive too. :)

The SGN() function is great and seems to be optimal for this task, couldn't find anything better. :)
The efficiency of SGN() deserves some additional common basic optimizations ...

Code: Select all

10 cls
15 bm=65536
20 line input"start address (dec) >";m$
30 l=len(m$):if l<1 or l>5 then 10
40 fori=1tol:m=asc(mid$(m$,i,1)):if m<48 or m>57 then 10 else next
50 m=val(m$):if m<0 or m>=bm then 10
55 b0=1:b1=2:b2=4:b3=8:b4=16:b5=32:b6=64:b7=128
60 for a=m to m+14
70 if a>=bm then a=a-bm
80 t=peek(a):print right$("0000"+mid$(str$(a),2),5)" ";
90 print sgn(b7 andt)sgn(b6 andt)sgn(b5 andt)sgn(b4 andt)sgn(b3 andt)sgn(b2 andt)sgn(b1 andt)(b0 andt):next
100 goto20
What's changed:
  • Constant values has been mapped to variables to prevent the costly string-to-float conversion.
  • The iterative address-value formating has been replaced by non-iterative approach.
  • Most of the calculations are performed outside the loop now and for-next is left responsible for incrementation.
;)

Timings for comparisons (regarding the SGN() expression in line 90)
1.42 SGN(T AND 128);
1.40 SGN(128ANDT)
1.33 SGN(B7 ANDT)
The measurement is based on the whole loop including screen output - just to see the relation to each other.
The dragon on my side: http://klasek.at/hc/dragon/
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: BASIC: byte value to bits...

Post by zephyr »

JeeK wrote:I'm obsessive too. :)

What's changed:
  • Constant values has been mapped to variables to prevent the costly string-to-float conversion.
  • The iterative address-value formating has been replaced by non-iterative approach.
  • Most of the calculations are performed outside the loop now and for-next is left responsible for incrementation.
;)

Timings for comparisons (regarding the SGN() expression in line 90)
1.42 SGN(T AND 128);
1.40 SGN(128ANDT)
1.33 SGN(B7 ANDT)
The measurement is based on the whole loop including screen output - just to see the relation to each other.
Your mods have introduced a bug to the code. Try entering 65522 or higher as your start address. :)
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: BASIC: byte value to bits...

Post by JeeK »

zephyr wrote:[..]
Your mods have introduced a bug to the code. Try entering 65522 or higher as your start address. :)
Damn, you are right. Should be corrected by

Code: Select all

60 for p=m to m+14
70 if p>=bm then a=p-bm else a=p
Not a good idea to manipulate the counter variable (at least in this case) ;)
The dragon on my side: http://klasek.at/hc/dragon/
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: BASIC: byte value to bits...

Post by zephyr »

I have further improved the display speed by adding a small machine code routine to the BASIC program. Both .CAS files are attached.

Hexadecimal example

Code: Select all

10 CLS:FOR I=512 TO 687:READ M$:POKE I,VAL("&H"+M$):NEXT
20 LINE INPUT"START ADDRESS (HEX) >";M$
30 IF M$="" THEN CLS:GOTO20
40 M=VAL("&H"+M$):A=INT(M/256):B=((M/256)-A)*256:POKE232,A:POKE233,B:EXEC512:GOTO20
50 DATA BD,BA,77,C6,F,9E,E8,F,6F,34,14,8D,A,35,14,8D,32,30,1,5A,26,F3,39,8C,10,0,24,1D,CC,70,70,DE,88,8C,1,0,25,4,A7,C0,20
60 DATA D,8C,0,10,25,4,ED,C1,20,4,A7,C0,ED,C1,DF,88,9F,52,8E,90,E8,34,16,7E,A0,11,34,10,A6,84,8E,60,70,10,8E,60,71,DE,88,33
70 DATA 45,85,80,26,4,AF,C1,20,3,10,AF,C1,85,40,26,4,AF,C1,20,3,10,AF,C1,85,20,26,4,AF,C1,20,3,10,AF,C1,85,10,26,4,AF,C1,20
80 DATA 3,10,AF,C1,85,8,26,4,AF,C1,20,3,10,AF,C1,85,4,26,4,AF,C1,20,3,10,AF,C1,85,2,26,4,AF,C1,20,3,10,AF,C1,85,1,26,4,AF
90 DATA C1,20,3,10,AF,C1,33,47,DF,88,35,90
Decimal example

Code: Select all

10 CLS:FOR I=512 TO 693:READ M$:POKE I,VAL("&H"+M$):NEXT
20 LINE INPUT"START ADDRESS (DEC) >";M$
30 L=LEN(M$):IF L<1 OR L>5 THEN 70
40 FORI=1TOL:M=ASC(MID$(M$,I,1)):IF M<48 OR M>57 THEN 70 ELSE NEXT
50 M=VAL(M$):IF M<0 OR M>65535 THEN 70
60 A=INT(M/256):B=((M/256)-A)*256:POKE232,A:POKE233,B:EXEC512:GOTO20
70 CLS:GOTO20
80 DATA BD,BA,77,C6,F,9E,E8,F,6F,34,14,8D,A,35,14,8D,38,30,1,5A,26,F3,39,8C,27,10,24,28,CC,70,70,DE,88,8C,3,E8,25,4,A7,C0
90 DATA 20,18,8C,0,64,25,4,ED,C1,20,F,8C,0,A,25,6,A7,C0,ED,C1,20,4,ED,C1,ED,C1,DF,88,1F,10,7E,95,7A,34,10,A6,84,8E,60,70,10
100 DATA 8E,60,71,DE,88,33,44,85,80,26,4,AF,C1,20,3,10,AF,C1,85,40,26,4,AF,C1,20,3,10,AF,C1,85,20,26,4,AF,C1,20,3,10,AF,C1
110 DATA 85,10,26,4,AF,C1,20,3,10,AF,C1,85,8,26,4,AF,C1,20,3,10,AF,C1,85,4,26,4,AF,C1,20,3,10,AF,C1,85,2,26,4,AF,C1,20,3,10
120 DATA AF,C1,85,1,26,4,AF,C1,20,3,10,AF,C1,33,47,DF,88,35,90
Attachments
ZEPHYR-BITS4.zip
(469 Bytes) Downloaded 255 times
ZEPHYR-BITS4D.zip
(544 Bytes) Downloaded 266 times
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: BASIC: byte value to bits...

Post by jedie »

@zephyr: That's too much machine code for me :oops:

I improved the look, by using lowcase / inverted letters. Looks like this:
Image


Source code is here: https://github.com/jedie/PyDragon32/blo ... C_NEGA.bas

It's a CC test with NEGA
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
Post Reply