Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Passing arguments

Author
Message
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 6th Sep 2003 22:00
I cannot get my var's to stay global, or public when moving into and out of funtions.
Here is an example: I am writing a NES emulator but wanting to use funtions instead of subs.

Function lsr6502()
adrmode (opcode)
value = get6502memory(savepc)

P = ((P And &HFE) Or (value And &H1))

value = value \ 2
put6502memory (savepc), value And &HFF

If (value = Not 0) Then
P = (P And &HFD)
Else
P = (P Or &H2)
End If
If ((value And &H80) = &H80) Then
P = (P Or &H80)
Else
P = (P And &H7F)
End If
End Function

When calling funtions using this format from main my global var's get corrupt or not changed like should. Any idea to make me more sensible to Dark Basic?
Ian T
23
Years of Service
User Offline
Joined: 12th Sep 2002
Location: Around
Posted: 6th Sep 2003 22:17
Um... well the first thing I noticed is that it's Endif not End If... That'd call the End command and terminate your program. Same thing with Endfunction. Also, if you're doing it like this:

If
Stuff
Endif

There should be no 'then'. 'then' should only be used if it's like this:

If Then Stuff (no endif)

So properly, that code is:



If (value = Not 0)
P = (P And &HFD)
Else
P = (P Or &H2)
Endif
If ((value And &H80) = &H80)
P = (P Or &H80)
Else
P = (P And &H7F)
Endif
Endfunction

--Mouse: Famous (Avatarless) Fighting Furball
Read It: http://www.angryflower.com/itsits.gif
Learn It: http://www.angryflower.com/bobsqu.gif
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 7th Sep 2003 00:02
Hey, thanks, I was programming for the wrong version of basic, its been awhile. have lots of code to change now.
Kevin Picone
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Australia
Posted: 7th Sep 2003 05:56
TRS80Model1:

I'm curious about two things..

A) Why not use use a Look up table, rather man handle the bits. The Cpu flags can just be masked on also..

B) Was the TRS model1 based on the 6809. Nice chip. It's a pity the C64/C128 didn't have one, back in it's hey day.

Kevin Picone
Play Basic - Visible Worlds - Kyruss II
[url]www.underwaredesign.com[/url]
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 7th Sep 2003 06:18
Trs80 Model 1 had the z80-a 1 mhz cpu which is the grandfather of the 8080 then became the 8086, then 8088, then 80186, 80286, 80386, 80486, 80586, 80686, etc. The original, weak, I wish modern windows was built ontop of the powerful 68b09 instruction set, but apple grabbed it and ruined the power it could have been with the unpopular mac.
CloseToPerfect
23
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 7th Sep 2003 09:16
I thought the z80 had a diffrent reg set then the x86 family, I never new the were simularities. The only reason the x86 family became popular was the increditable rise in PC clones because IBM didn't use a propirity system like apple, which in turn also led to the mass demand for ms-dos and built the foundation for microsoft. funny has things happen.

CTP
OSX Using Happy Dude
22
Years of Service
User Offline
Joined: 21st Aug 2003
Location: At home
Posted: 7th Sep 2003 12:04
Quote: "I thought the z80 had a diffrent reg set then the x86 family"

I does - I dont think Intel designed the 8086/8088 as a successor to Zilog's Z80 - as far as I know, Intel designed it on their own (and badly designed it was too).


Avatar & Logo by Indi. Come to the UK DBPro Convention in Chichester
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 9th Sep 2003 04:12
As a lot of the time I was wrong, the z80 was a improved copy of the intel 8080 with 80 new documented opcodes and new opcodes that did not funtion on every chip. The z80 was able to execute all opcodes of the 8080 plus 80 documented opcodes that belonged to z80.
DrakeX
23
Years of Service
User Offline
Joined: 26th Aug 2002
Location:
Posted: 9th Sep 2003 04:23
to use hex values in DBP you have to use 0x, not &H. that's a zero, not a capital O, BTW

Function lsr6502()
adrmode (opcode)
value = get6502memory(savepc)

P = ((P And 0xFE) Or (value And 0x1))

value = value \ 2
put6502memory (savepc), value And 0xFF


If (value = Not 0)
P = (P And 0xFD)
Else
P = (P Or 0x2)
Endif
If ((value And 0x80) = 0x80)
P = (P Or 0x80)
Else
P = (P And 0x7F)
Endif
Endfunction

stop looking at me!
TRS80Model1
23
Years of Service
User Offline
Joined: 2nd Feb 2003
Location: - Please Select -
Posted: 9th Sep 2003 08:05
Hey thanks drake, you have helped me more than once I think, I am now returning a predictable result. If this emulator works at full speed I will really be impressed by dbpro, and it may impress others as well. 65c02 emulator is now working at 300 mhz. may be able to integrate the complete hardware at full speed. 1300 lines of code so far. May need hardware freaks to finish this thing.

Login to post a reply

Server time is: 2026-07-25 09:38:51
Your offset time is: 2026-07-25 09:38:51