dmsc / fastbasic

FastBasic - Fast BASIC interpreter for the Atari 8-bit computers
GNU General Public License v2.0
139 stars 20 forks source link

Question re: Using some other means to get STATUS #98

Closed rickcollette closed 3 weeks ago

rickcollette commented 3 weeks ago

I am trying to get the R: device to work properly.

However, I cannot seem to duplicate the functionality of Atari BASICs "status" command.

In atari basic, we would request status of IOCB,intvar

Then we could peek at the memory location (747, 748, 749)

I have been trying to accomplish this via XIO; but I'm just not getting the result i am hoping for. Ultimately, I would love to tell when there is an incoming call to R:, then perform some action based on that.

I have been trying for a couple of days to get this nailed down. After a lot of trial and error, this is what I have arrived at, but it is not working either.

Maybe someone else can explain this to me?

' Trying to duplicate Atari Basic STATUS command
' Define constants and initialize variables
PROC InitializeVariables
  ' Constants
  C0 = 0 : C1 = 1 : C2 = 2 : C3 = 3 : C4 = 4 : C5 = 5 : C6 = 6 : C7 = 7 : C8 = 8 : C9 = 9
  C10 = 10 : C13 = 13 : C14 = 14 : C16 = 16 : C24 = 24 : C32 = 32 : C34 = 34 : C36 = 36
  C38 = 38 : C39 = 39 : C40 = 40 : C64 = 64 : C80 = 80 : C119 = 119 : C120 = 120
  C121 = 121 : C126 = 126 : C127 = 127 : C128 = 128 : C195 = 195 : C253 = 253 : C255 = 255
  C256 = 256

  ' Initialize variables
  FileNum = C1 : Modem = C2 : InMo = 0
  Inm = 747 : Ink = 764

  ' More string variables
  DIM Cr$, Bel$, Del$, Bs$, X, Temp$, A

  Cr$ = CHR$(155)

  ' Initialize control variables
  GRAPHICS 0

ENDPROC

' Main execution starts here
PROC Main
  @InitializeVariables
  @InitPrinter
  @InitModem
DO
  @ModemStatus
LOOP
ENDPROC

PROC InitModem
  @ClearStatus
  POS. 0,7:? "Initializing Modem"
  XIO #Modem, C38, C0, C0, "R:"
  XIO #Modem, C34, C128, C0, "R:"
  OPEN #Modem, 15, C0, "R:":CurrErr = ERR()
  IF NOT (CurrErr = 1)
    ? "Error opening modem device: "; CurrErr
    Exit
  ELSE
    XIO #Modem, C40, C0, C0, "R:"
    ?"Modem Up"
  ENDIF
  ? #C4, "Open modem done"

  XIO #Modem, C40, C0, C0, "R:"
  ? #Modem, "ATZ"
  ? #Modem, "ATS0=1"
  ? #Modem, "ATE0 S4=24 S2=255 S7=5 S37=10"
  PAUSE 40
  POKE 77, C0 : POKE 752, C1
  POKE 53279,8
  @ClearStatus
  POS. 8,0:? "Modem Initialization Complete"
ENDPROC

PROC ClearStatus
POS. 0,0:?"STATUS:                               "
ENDPROC

PROC ModemStatus
  OPEN #Modem,13,0,"R:"
  XIO #1,13,0,0,"R:"
  X = PEEK(749)
  Y = PEEK(747)
  Z = PEEK(748)

  PRINT #C4,"(749)=";X
  POS. 8,0:? "(749)=";X
  PRINT  #C4,"(747)=";Y
  POS. 16,0:? " | (747)=";Y
  PRINT  #C4,"(748)=";Z
  POS. 27,0:? " | (748)=";Y
ENDPROC

' Using the printer for debugging
PROC InitPrinter
OPEN #C4, C8, C0, "P:"
  IF ERR() <> 1 THEN
    ? "Error opening printer device."
  ?#C4,"Printer Online"
ENDPROC

@Main
rickcollette commented 3 weeks ago

for some reason i could not find the original question - now i can.. closing this as "holy cow i cant use the internet..."

bhall408 commented 3 weeks ago

Devices work with IOCBs (IO control blocks).

You also have channels so that you can open more than one at a time.

I don’t know fastbasic, but the below looks like you are using channel “modem” for the open, but then channel 1 for the XIO call, and “#modem” is defined as 2.

So you are opening using channel 1, and doing XIO with channel 2 if I am interpreting that correctly.

It is also good practice to check the error returns from each of open and XIO. For example, if the channel is already open any something else, you’d get an error. The XIO may also be returning a useful error code that would help you debug the code - for example, “not open”.

On Nov 3, 2024, at 1:44 PM, Rick Collette @.***> wrote:

PROC ModemStatus OPEN #Modem,13,0,"R:" XIO #1,13,0,0,"R:" X = PEEK(749) Y = PEEK(747) Z = PEEK(748)

rickcollette commented 3 weeks ago

Yeah - thank you - oversight in the paste i did.. forgot to change the #1 to #Modem.

So whats happening, those valuse for 747 and 747 increment up to 32; then sit there. Even after a disconnect - which it does not seem to to want to recognize - altirra just locks up. I am using the altirra RHND850 for the r:handler.

have not tried on real hardware.

dmsc commented 3 weeks ago

Hi!

I am trying to get the R: device to work properly.

However, I cannot seem to duplicate the functionality of Atari BASICs "status" command.

I see that you already answered this part.

But I have some comments on your code:


' Trying to duplicate Atari Basic STATUS command
' Define constants and initialize variables
PROC InitializeVariables
  ' Constants
  C0 = 0 : C1 = 1 : C2 = 2 : C3 = 3 : C4 = 4 : C5 = 5 : C6 = 6 : C7 = 7 : C8 = 8 : C9 = 9
  C10 = 10 : C13 = 13 : C14 = 14 : C16 = 16 : C24 = 24 : C32 = 32 : C34 = 34 : C36 = 36

This will produce bigger and slower code in FastBasic that simply using the constants as is.

Loading the number 0 or 1 uses one byte. Loading numbers from 2 to 255, uses two bytes. Loading the value from one variable, also uses two bytes, but it is slower than a number.

So, this will only make your code smaller if you are using this for numbers bigger than 256, were loading the number will be 3 bytes, and only if you use the number may times.

Have Fun!

rickcollette commented 3 weeks ago

Thats awesome to know - I always had a dislike for that bit in atari basic. This will make it cleaner for me.