|
Post by stiggity on Oct 20, 2022 4:18:39 GMT
How can I multiply a value x 254, and then display the sum? lets say 600x254, store it all someplace and then display to screen? again, any sort of help is greatly appreciated..
|
|
|
Post by mirkosoft on Oct 20, 2022 22:52:47 GMT
to print 16-bit digit it is simple, ĸernal128 call $8E32 Prints 16-bit digit X=LO/A=HI
|
|
|
Post by stiggity on Oct 21, 2022 2:01:57 GMT
Mirkosoft: Thank you. i guess the hard part is this.. im looping anywhere from 1 to 500 times. each loop i want to add #128 to an address(s)? so for every loop, i add 128 to a principle address, and continue, until I've reached 600. While each loop, I want to print the additions current value.
00000 - 00128 - 00256 - 00384 - 00512
but only update to one screen location. I have it running, but i cannot figure out how to do the math. I mean lda address(s) clc adc#128 sta $address(s) but im sure any address can only house an 8bit number, and getting the math right, to deal with 2 address's, right now, is the trouble i've ran into.
Thanks for reading, thanks for listening.. any sort of assistance is greatly appreciated..
|
|
|
Post by stiggity on Oct 22, 2022 15:04:45 GMT
i got it working.. took me quite awhile, but i was navigating into uncharted waters.
Mirk? TY!!!
|
|
|
Post by c128old on Oct 22, 2022 15:06:45 GMT
For 6502 one needs two bytes: low and high Everytime your lowbyte ADC gives carry you need to add one to the high byte.
Addto16bit: LDA lowbyte ; byte 1 location CLC ADC #value ; 128 in your example STA lowbyte BCS addhi RTS INC hibyte ; byte 2 location RTS
You will find examples on 6502 programming sites.
|
|
|
Post by stiggity on Oct 22, 2022 15:09:28 GMT
c128old: Much appreciated... either my search criteria is off, or were on different Interwebs.. i cudnt find anything..
|
|
|
Post by stiggity on Oct 22, 2022 16:33:26 GMT
c128old, the snippet you posted above works great, but only 511 times... i guess being able to count into the hundreds of thousands needs a 3rd byte? lowb/hib/hib2? and once hibyte reaches 255, reset and add 1 t hibyte2? if i could get low/hi,hi2 into an A, Y, X format i would be ahead of the game, but it's not working. Any more insight is appreciated.
|
|
|
Post by c128old on Oct 22, 2022 18:13:14 GMT
stiggity,
Let's start with the 'obvious 3 byte' extension:
lowbyte = $FC midbyte = $FB hibyte = $FA value = 128
Addto24bit: LDA lowbyte ; byte 1 location CLC ADC #value ; 128 in your example STA lowbyte BCS addmid ; the addition caused carry (to next byte) RTS addmid: INC mibyte ; byte 2 location BEQ addhi ; mid byte reached zero after inc (now 0, next one must increase) RTS addhi: INC hibyte ; highest counting byte (byte 3) RTS
Of course, you can increase this into a longer list of values. Think about how a digital clock counts up. Make the byte-counter (inc by max 1 byte) for an 'arbitrarily' (see note below) large value:
NRbytes = 15
AddtoNbytes: LDX #0 ; first table entry LDA table,X ; lowest byte CLC ADC #value ; 128 in your example STA table,X BCS addloop ; the addition caused carry (to next byte) done: RTS
addloop: CPX #nrbytes BEQ done INX INC table,X BEQ addloop ; zero? then add to the next one
NOTE: You can now handle an entire page of 256 bytes worth of values. That's a 2048 bits value (2 to the power 2048, which is -a lot- : 32317006071311007300714876688669951960444102669715484032130345427524655138867890893197201411522913463688717960921898019494119559150490921095088152386448283120630877367300996091750197750389652106796057638384067568276792218642619756161838094338476170470581645852036305042887575891541065808607552399123930385521914333389668342420684974786564569494856176035326322058077805659331026192708460314150258592864177116725943603718461857357598351152301645904403697613233287231227125684710820209725157101726931323469678542580656697935045997268352998638215525166389437335543602135433229604645318478604952148193555853611059596230656L) I think the work needed to actually show this on screen would be something. Also this will take a 2Mhz 8502 quite some time.
Now you are asking to do this within the set of 6205 registers. That is really not the strength of this processor's design, but hey:
: IN A lowest byte : IN X mid byte : IN Y hi byte : add hard-coded 'value' CLC ADC #value BCC done ; if no carry, then get out INX ; adding 'the carry from ADC' to X BNE done ; if not zero, then we are done INY ; adding 'the X carry' to Y done: RTS ; exit of subroutine A = updated value, X = maybe increased, Y = maybe increased
Note that even if you put your table (in the previous example) in the zeropage, this AXY routine is of course a bit faster. Doing an 'INC absolute,X' costs 7 clocks, the most expensive instructions available! The zeropage-mode on 6502 is powerful (think of it as an entire page of registers, at cost of 1 added clock), but the read/write instructions are of course slower. ADC# and INX/Y are only 2 clocks and the branch instructions too.
|
|
|
Post by stiggity on Oct 22, 2022 19:34:11 GMT
C128OLD!! NICE! what i was working with was similar, but im learning about the carry bit. How on earth can we get
lowbyte = $FC midbyte = $FB hibyte = $FA
onto the screen... I would share what I'm working with, but I get embarrassed, and am soft in that department..
|
|
|
Post by stiggity on Oct 22, 2022 20:44:39 GMT
I'm going to share the code I'm working with/on. please let me tidy it up a little.
give me a couple hours..
|
|