BASIC's USR routine to run Diamond function (revised)
ITEM 1
I made a reference, in my last blog entry, to a USR call to run a Diamond function from Atari BASIC. In assembly language you would set the data and pointers required by the Diamond function, place the function number in the accumulator, then jump to Diamond at $E800. In BASIC you set the data and pointer data as defined by B0-B7 and W0-W7, then call a machine language routine that BASIC loaded into page 6 memory. Because Diamond and BASIC both use the same Zero page addresses, when jumping from BASIC to Diamond the BASIC data in those locations has to be saved and the Diamond data has to be relocated into those addresses before the jump to $E800. Then the BASIC data has to be moved back into Page 0 before BASIC takes control of program flow.
I have edited out the reference but want to apologize for any confusion that my last blog entry may have caused or that which has been caused by the last paragraph.
ITEM 2
I was playing around, trying to get BASLOADR.APP to work. This was a program that would take the file name of a BASIC program and save it along with ml code that would act like an AUTORUN.SYS file to run the BASIC program when quitting from Diamond. It didn't work. Then I hit the scroll-lock key and it worked. I guess I have some more experimenting to do. Right now it looks like it will work with both Diamond 2.0 and 3.0.
ITEM 3
I need a solution to the fact my short term memory just isn't what it use to be. Sometimes I can remember a file name of a BASIC program that I want to run, quit out of Diamond, type - RUN “D:FILENAME.BAS”, and it runs. And sometimes I can't.
I have written a BASIC program that uses the Diamond File Select Routine to load a list of files with the .BAS extension, select the file with a click of the button and then click the run button. I seem to be able to remember RUN “D:MENU.BAS”.
I am not sure if the program got published but I was going to update it to run with both the DEVELOP.BAS and a public domain SHELL.BAS from DIABASIC.ARC. I haven't done that yet 'cause I wanted to find out what the differences between the ml-PAGE 6 routines were. To do that I had to de-compile the ml routines. (I checked the DEVELOP.BAS programs on the development kits for Diamond 2.0 and 3.0 and they are the same program.)
Although there are programs that can de-compile compiled Assembly programs, doing it by hand has its challenges.
ITEM 4
Having read almost every book on Assembly language for the Atari and the Boot Camp series in Analog Computing, I felt like I had learned a lot. It wasn't until I de-compiled the 49 Second Screen Dump from Compute! for a Diamond accessory by hand did I feet like I was starting to understand Assembly language. So, when I decided to compare the BASIC shell USR calls contained in the two shell programs it seemed like the way to go.
I assembled the needed aids. Pencil (with eraser), Paper(lined), “The Analog Computing Pocket Reference Card c1985” (Code Translation Table is quite helpful), Book on machine language (I used Machine Language For Beginners by Richard Mansfield) and Mapping The Atari (in case the program references memory locations).
The Code Translation table can be used to convert numbers between decimal and hexadecimal but I have been using the Texas Instruments TI-34 calculator to make the conversions plus it has the ability to do binary math and octal conversions. A new one will cost about $50 on Amazon or $10 for a used one. Some of the free phone apps will make the conversions for free.
The most important thing you need is a print out of the numbers that make up the ml routine.
The shell program that came with development kit for was called DEVELOP.BAS. The routine is contained in the data statements at the end of the program. READ the data then POKE it into Page 6. Between the POKE X,Y and NEXT X commands add the command “PRINT X,Y:”. Run the program and the Address and BYTE data will print to screen. Use LPRINT if you have a printer.
The code for the public domain program iis contained in the file DIABASIC.OBJ. The SHELL.BAS program opens this file and calculates the Address for each Byte. Again, add the print command between the POKE and NEXT (line 24) and then run the program. I used the scroll lock and wrote down the code. If it had been any longer I might have gotten out the printer. Also you should change the error in defining W4 in line 31. W4 should equal 1547.
Now its just a matter of looking up the fist byte in the Code Translation Table to see if there is an Assembly instruction associated with the number. The Addressing Mode will tell what to do with the next bytes. Knowing the addressing modes is a must and should be learned before attempting this. The Branching instructions should be reviewed at least once ever 15 years, I have yet to master those calculations(but I'm getting close).
Below is listed the code for the 2 URL calls. Feel free to check my work. The two routines do the same thing in two different ways. The only real difference is that in DIABASIC.OBJ a byte location PORTB, something to do with memory bank switching, is saved and restored. Knowing this could prove important at a future date.
DEVELOP.BAS from Diamond 2.0 developer's kit. Addresshex Dec Instruction ASM Comment0600 1536 76,27,6 JMP $061B ;Jump over data bytes0603 ;24 bytes to hold information Address variable W0-W7061A ; bit data in B0-B70601B 1563 32,36,06 JSR $0624 ;swap data 1566 104 PLA 1567 104 PLA 1568 104 PLA 1569 32,0,142 JSR $8E00 ;call diamond function0624 1572 162,23 LDX #23 ;swap data back (pass 2)0626 1574 189,03,06 LDA $06038,X 1577 168 TAY 1578 181,128 LDA $80,X 1580 157,03,06 STA $0603,X 1583 152 TAY 1584 149,128 STA $80,X 1586 202 DEX 1587 16,241 BPL $0602 ; - 15 Bytes 1589 96 RTSDIABASIC.OBJ from DIABASIC.ARC - Public Domain Addresshex Dec Instruction ASM Comment0600 1536 76,27,6 JMP $0633 ;JUMP OVER 48 BYTES0603 1593 ;Holds data for page 0 that is used0632 1886 ;by diamond and basic0633 1587 104 PLA 1588 162,0 LDX #00630 1590 181,128 LDA $80,X 1592 157,27,6 STA $061B,X 1595 189,3,6 LDA $0603,X 1598 149,128 STA $80,X 1600 232 INX 1601 224,24 CPX #24 1603 208,241 BNE $0636 ; -14 BYTES 1605 173,1,211 LDA $D301 ;PORTB - bank switch 1608 9,2 ORA #2 1610 141,1,211 STA $D301 1613 104 PLA 1614 104 PLA 1615 32,0,142 JSR $8E00 ;JUMP TO DIAMOND 1618 173,1,211 LDA $D301 1621 41,253 AND #253 1623 141,1,211 STA $D301 1626 162,0 LDX #0065C 1628 181,128 LDA $80,X 1630 157,3,6 STA $0603,X 1633 189,27,6 LDA $061B,X 1636 149,128 STA $80,X 1638 232 INX 1639 224,24 CPX #24 1641 208,241 BNE $065C; -14 BYTES 1643 96 JSR
0 Comments
Recommended Comments
There are no comments to display.