Dark Bit Factory & Gravity
PROGRAMMING => Other languages => ASM => Topic started by: Stonemonkey on April 05, 2008
-
Since the other thread on this is in useful links I thought I'd start a new one here on the 6502.
I'm trying to come up with some routines to be used in a little pseudo 3d graphics experiment on the acorn electron.
Here's my first attempt, it multiplies 2 16 bit unsigned integers and gives a 32 bit result
LDX #&10
LDA #&00
STA &74
STA &75
STA &76
STA &77
STA &78
STA &79
.mult_loop ROR &71
ROR &70
BCC skip_mult_add
CLC
LDA &72
ADC &76
STA &76
LDA &73
ADC &77
STA &77
LDA &74
ADC &78
STA &78
LDA &75
ADC &79
STA &79
.skip_mult_add CLC
ROL &72
ROL &73
ROL &74
ROL &75
DEX
BNE mult_loop
RTS
Just looking at this for a simple multiply gives some idea of the task ahead.
-
Think I'm going to try it with 24 bit (16:8) fixed point.
Been using electrem emulator, http://electrem.emuunlim.com/ just an older version of that but gonna give this a go as it's windowed.
-
Whats the mnemonic for call in 6502? I wanna see this workin
LOL that emulator doesnt use the systems keyboard drivers I cos I dont use a Qwerty Keyboard Layout I much prefer the Dvorak layout (Much faster and doesnt cause repetetive strain disorder) But when I type "',.pyf" i get "qwerty" instead
-
That code has to be written into the BASIC code with line numbers inside [ ] and looped through twice to assemble it as there's a branch forward.
Here's the file that can be loaded in, type RUN to run it or for example LIST 10,100 to view lines 10 to 100
Welcome to the past.
-
I've been having a problem with that windowed emulator, I'll have a look and see if there's any better ones.
-
So if either of the 2 inputs is negative then I can use 2s compliment on them, do the multiply then use 2's compliment on the result unless both inputs are negative in which case the result can be left as it is.
Are there any tricks that can be done, for example if both inputs are negative or any cases like that?
-
Heres an example of signed comparisons greater than one byte might be useful
http://6502.org/tutorials/compare_beyond.html#6
-
Looking through that there's probably a lot of handy tips in there, thanks. K+
-
Here's something like I'm planning on using for divide although it's a test in freebasic code so those comparisons might come in handy.
dim as unsigned integer a,b,result,m
randomize timer
a=rnd*2000+100
b=rnd*100
print a;"/";b;"=";a\b
print
m=1
while (b shl 1)<=a
b shl=1
m shl=1
wend
while m>0
if a>=b then
result or=m
a-=b
end if
b shr=1
m shr=1
wend
print "my result=";result;" remainder ";a
sleep
end
-
This might be a good link for you guys:
http://www.6502asm.com/
even comes with a little screen starting at address $200 :)
-
Cool, thanks.
Just found the electron stuff on my HDD again and thought about some retro coding again.
-
I'm still thinking I want to do something on this, I've just been playing around with some ideas and have some graphics stuff working although it's all pretty crude atm and that screen mapping is a bit of a challenge to work with so I'm just going to stick to 1 mode, probably mode 5.
I'm going to see what I can get working along the lines of sprites and scrolling, maybe some sort of double buffering isn't out of the question.
If anyone with some experience of the electron or bbc wants to lend a hand that'd be great, and I'll put up all my code although it'll be in the uef files from the emulator.
Fryer
-
I coded for both those machines but that was a loooooooooong time ago. :crutches: If I can help, I will.
Jim
-
Hi Jim, and thanks.
For the first time, I think I've just worked out how to double buffer, I could never get things in the right place before but this seems to work.
in MODE 5 (10k per buffer, 4 colour lo res) with HIMEM=12288
*FX19
?&FE03=&58
'displays memory from &3000-&57FF
*FX19
?&FE03=&80
'displays memory from &5800-&7FFF
-
8 colours in mode 5 (sort of) using the event timer to switch the palette partway down the screen, unfortunately the palette switching is a bit slow for each colour so they don't all change at the same position on the screen. Because the switching is event driven the effect continues after the program has finished running.
-
:)
The BBC version of Elite used to switch modes half way down the screen - the 3d in 2 colours up top and a 4 colour HUD underneath - mode 4 and mode 5.
The Electron couldn't do this trick though, for some reason.
Jim
-
Yep, I'm not sure of the reason for that. Atm I don't have much control over where the palette change happens, it's a low res timer (100 Hz) so I only get 1 point slightly above the middle where i can make the change and that will probably get a bit wobbly if there's any other interrupts occurring, I have seen the suggestion of using the flashing colours and using the event to switch between displaying the mark/space colours so they all change at the same point. I've not tried switching modes yet and I suspect there's going to be more to it than the palette changes.
Another trick used though was in Firetrack, normally the hardware only allows vertical scrolling 8 lines at a time which isn't too smooth, all the graphics modes have the same vertical res but the text modes have 2 pixel gaps between each character row so they had it set to text mode at the top of the screen and somehow controlled how far down the screen it switched to graphics mode so the number of 2 pixel gaps could give 2 pixel vertical scrolling.
I've seen that the BBC has higher res timers than 100Hz but I'm not sure if there's some equivelent on the electron, maybe the firetrack thing was just done by counting clock cycles of the code rather than using interrupts.
-
Got a simple scroller working, it's double buffered and scrolls the same thing along the top and bottom of the screen although it's just garbage that's being scrolled atm. I need to come up with some sort of font now, I'm thinking to save memory that instead of a whole bitmap for each character, the characters could be made up from blocks put together.