diff --git a/README.md b/README.md index 99e8d19..d32c782 100755 --- a/README.md +++ b/README.md @@ -1,3 +1,8 @@ +# 1/10/2020 PLASMA 2.0 Developer Preview 3 Available! +[Download and read the Release Notes](https://github.com/dschmenk/PLASMA/releases) + +[Change List](https://github.com/dschmenk/PLASMA/blob/master/doc/Version%202.0.md#changes-in-plasma-for-20-dp-3) + # 4/29/2018 PLASMA 1.2 Available! [Download and read the Release Notes](https://github.com/dschmenk/PLASMA/blob/master/doc/Version%201.2.md) diff --git a/doc/Editor.md b/doc/Editor.md index 4d0b5f0..115fbb9 100644 --- a/doc/Editor.md +++ b/doc/Editor.md @@ -2,8 +2,8 @@ WELCOME TO THE PLASMA EDITOR! ============================= FIRST THINGS FIRST: -TO NAVIGATE, USE THE ARROW KEYS. ON THE -APPLE ][: +TO NAVIGATE, USE THE ARROW KEYS. ON +THE APPLE ][: CTRL-K = UP CTRL-J = DOWN. @@ -18,22 +18,23 @@ TO JUMP AROUND THE TEXT FILE USE: CTRL-Q = JUMP BEGINNING CTRL-E = JUMP END -THE 'ESCAPE' KEY WILL PUT YOU IN COMMAND -MODE. FROM THERE YOU CAN EXIT BY -ENTERING 'Q' AND 'RETURN'. YOU CAN ALSO -RETURN TO THE EDITOR BY JUST PRESSING -'RETURN'. +THE 'ESCAPE' KEY WILL PUT YOU IN +COMMAND MODE. FROM THERE YOU CAN +EXIT BY ENTERING 'Q' AND 'RETURN'. +YOU CAN ALSO RETURN TO THE EDITOR BY +JUST PRESSING 'RETURN'. ------- THE PLASMA EDITOR IS A SIMPLE TEXT EDITOR FOR ENTERING AND MANIPULATING -TEXT AND SOURCE CODE FILES. THE EDITOR -ONLY SUPPORTS 40 COLUMN TEXT ALTHOUGH -LINES CAN BE UP TO 79 CHARACTERS LONG. -THE SCREEN WILL SCROLL HORIZONTALLY -AS THE CURSOR MOVES. THERE IS 16K OF -MEMORY FOR THE TEXT BUFFER. +TEXT AND SOURCE CODE FILES. THE +EDITOR ONLY SUPPORTS 40 COLUMN TEXT +ALTHOUGH LINES CAN BE UP TO 79 +CHARACTERS LONG. THE SCREEN WILL +SCROLL HORIZONTALLY AS THE CURSOR +MOVES. THERE IS 16K OF MEMORY FOR +THE TEXT BUFFER. IT HAS TWO MODES, COMMAND AND EDIT. @@ -52,13 +53,17 @@ EDIT COMMANDS: CTRL-Q = JUMP BEGIN CTRL-E = JUMP END CTRL-D = DELETE CHAR - CTRL-X = DELETE/CUT LINE - CTRL-V = COPY DELETED LINE + CTRL-B = BEGIN SELECTION + CTRL-C = COPY SELECTION INTO CLIPBOARD + CTRL-X = CUT SELECTION INTO CLIPBOARD + CTRL-V = PASTE CLIPBOARD CTRL-O = OPEN NEW LINE CTRL-F = OPEN A FOLLOWING NEW LINE CTRL-T = JOIN LINES - CTRL-B = TOGGLE INSERT/OVERWRITE + CTRL-Y = TOGGLE INSERT/OVERWRITE TAB/CTRL-I = INSERT SPACES TO NEXT TAB + = INDENT SELECTION IF INSERT MODE + = UNDENT SELECTION IF OVERWITE MODE ESCAPE = SWITCH TO COMMAND MODE DELETE = DELETE CHAR LEFT @@ -78,7 +83,7 @@ EDIT COMMANDS: APPLE ][, UPPER AND LOWER CASE ENTRY WORKS AS EXPECTED. - CTRL-C = FORCE LOWER-CASE CHARS + ESC T C = FORCE LOWER-CASE CHARS If you have a lower-case character generator installed, you can force @@ -93,11 +98,12 @@ EDIT COMMANDS: The 'SOLID-APPLE' key will modify theese keys: - SA-RETURN = OPEN LINE + SA-RETURN = OPEN FOLLOWING LINE SA-LEFT ARROW = JUMP LEFT SA-RIGHT ARROW = JUMP RIGHT SA-UP ARROR = JUMP UP SA-DOWN ARROW = JUMP DOWN + SA-TAB = DETAB Apple /// FEATURES: ------------------- @@ -106,11 +112,12 @@ EDIT COMMANDS: these keys: OA-\ = DELETE CHAR LEFT - OA-RETURN = OPEN LINE + OA-RETURN = OPEN FOLLOWING LINE OA-LEFT ARROW = JUMP LEFT OA-RIGHT ARROW = JUMP RIGHT OA-UP ARROR = JUMP UP OA-DOWN ARROW = JUMP DOWN + OA-TAB = DETAB On the keypad, 'OPEN-APPLE' allows the keys for navigation and misc: @@ -124,9 +131,9 @@ EDIT COMMANDS: OA-7 = JUMP BEGIN OA-1 = JUMP END OA-5 = DELETE CHAR - OA-- = DELETE/CUT LINE - OA-0 = COPY DELETED LINE - OA-ENTER = OPEN NEW LINE + OA-- = CUT SELECTION INTO CLIPBOARD + OA-0 = PASTE CLIPBOARD + OA-ENTER = OPEN FOLLOWING LINE OA-. = TOGGLE INSERT/OVERWRITE COMMAND MODE: @@ -142,5 +149,9 @@ COMMAND MODE: P = SET PREFIX H [SLOT] = HARDCOPY TO DEVICE IN SLOT (DEFAULT 1) N = CLEAR TEXT IN MEMORY + T G = TOGGLE GUTTER VIEW + T C = TOGGLE LOWER-CASE SUPPORT (APPLE ][) + G = GO TO LINE # + F [STRING] = FIND STRING E = EDIT MODE 'RETURN' = EDIT MODE diff --git a/doc/Version 2.0.md b/doc/Version 2.0.md new file mode 100644 index 0000000..7894a0c --- /dev/null +++ b/doc/Version 2.0.md @@ -0,0 +1,258 @@ +# PLASMA Version 2.0 Developer Preview 3 + +Welcome to PLASMA: the Grand Unifying Platform for the Apple 1, ][, and ///. + +Download the five disk images: + +[PLASMA 2.0 DP3 800K Full System](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA2.2mg?raw=true) + +[PLASMA 2.0 DP3 System and ProDOS Boot](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA2-SYS.PO?raw=true) + +[PLASMA 2.0 D3P Build Tools](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA2-BLD.PO?raw=true) + +[PLASMA 2.0 DP3 Demos](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA2-DEM.PO?raw=true) + +[PLASMA 2.0 DP3 TCP/IP network modules](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA2-INET.PO?raw=true) + +[PLASMA 2.0 DP3 Apple /// SOS Boot and SANE floating point modules](https://github.com/dschmenk/PLASMA/blob/master/images/apple/PLASMA2-FPSOS.PO?raw=true) + +PLASMA can be run from floppies, System in Drive 1, and Build or Demos in Drive 2. Mass storage is the recommended installation that looks like (replacing HARDISK with your volume name of choice): + +System Files => /HARDISK/PLASMA/ + +Build Files => /HARDISK/PLASMA/BLD/ + +Demo Files => /HARDISK/PLASMA/DEMOS/ + +SANE files => /HARDISK/PLASMA/SYS + +INET files => /HARDDISK/PLASMA/SYS + +Use the System Utilities to copy the floppy images into the above mentioned directories. + +## Apple 1 + +The Apple 1 is a very constrained system compared to the ][ and ///. It is required to have the CFFA1 disk adapter installed to provide file storage and a full 32K od RAM. To get the files onto the CF card required the use of [CiderPress](http://a2ciderpress.com) and they must be placed in one directory. Most PLASMA programs won't work on the Apple 1 due to limited filesystem support, video/graphics capabilities, and lack of audio output. It does, however, make a good place to start when porting PLASMA to a new platform. + +## Apple ][ + +To boot directly into PLASMA, you will need to put the system files in the root prefix of the boot device and make sure PLASMA.SYSTEM is the first SYSTEM file in the directory. Otherwise, start PLASMA.SYSTEM from your program launcher of choice. All Apple ][ models with 64K and two floppy drives are supported up to a maxed out IIGS with accelerator and hard drive. + +#### 65802/65816 Support + +PLASMA can utilize the 16 bit features of the 65802 and 65816 processors to improve performance of the PLASMA VM operation. This is transparent to the programmer/user and doesn't make any additional memory or capabilities available to PLASMA. PLASMA will automatically run the most optimal VM for your configuration. + +## Apple /// + +The Apple /// gets the environment it always wanted: The ability to navigate the filesystem with a command line interface. The Apple /// always boots from the floppy drive, even if a hard disk is installed. The PLASMA.SOS floppy should be updated with the SOS.DRIVER configured for your machine. Once booted, type `S /HARDISK/PLASMA` (or your install directory of choice) to change to, and set, the system directory. This can be automated by creating an `AUTORUN` file on the boot floppy with the above command in it. + +## PLASMA Command Line Shell + +PLASMA incorporates a very basic command line shell to facilitate navigating the filesystem and executing both SYSTEM/SOS programs and PLASMA modules. It has a few built-in commands: + +| Command | Operation | +|:----------------------------:|-------------------------| +| C [PREFIX] | Catalog prefix +| P \ | change to Prefix +| / | change to parent prefix +| V | show online Volumes +| S \ | set System prefix* +| +SOS \ [PREFIX] | launch SOS interpreter* +| -\ [PARAMS] | launch SYSTEM program** +| +\ [PARAMS] | exec PLASMA module +``` +[Optional parameters] + +* Apple /// only +** Apple ][ only +``` + +The shell is very brief with error messages. It is meant solely as a way to run programs that accept command line parameters and take up as little memory as possible. It does, however, provide a rich runtime for PLASMA modules. + +## Included Modules + +PLASMA comes with many library modules used by the tools, demos and sample code. The PLASMA system volume must remain in place for the duration of PLASMAs run otherwise it won't be able to find CMD or the system libraries. Probably the most useful included module is the editor. It is used for editing PLASMA source file, assembly source files, or any text file. Execute it with: +``` ++ED [TEXT FILE] +``` +The file manipulation utilities to copy, delete, rename, create directories, and change file type and aux type remove the need for external programs to do the same. PLASMA can now be installed with the tools included on the PLASMA2-SYS boot floppy. They are: +``` ++COPY [-R] + ++DEL [-R] ++REN ++NEWDIR ++TYPE [NEWTYPE [NEWAUX]] ++CAT [-R] [OUTPUT FILE] +``` +Compiler warnings are enabled with `-W`. The optional optimizer is enabled with `-O` and extra optimizations are enabled with `-O2`. The source code for a few sample programs are included. The big one, `RPNCALC.PLA`, is the sample RPN calculator that uses many of PLASMA's advanced features. The self-hosted compiler is the same compiler as the cross-compiler, just transcribed from C to PLASMA (yes, the self-hosted PLASMA compiler is written in PLASMA). It requires patience when compiling: it is a fairly large and extensive program. + +## Demos + +There are some demo programs included for your perusal. Check out `ROGUE` for some diversion. You can find the documentation here: https://github.com/dschmenk/PLASMA/blob/master/doc/Rogue%20Instructions.md. A music sequencer to play through a MockingBoard if it is detected, or the built-in speaker if not. A minimal Web server if you have an Uthernet2 card (required). Try `SPIDERS`for some hires shoot'em-up action. Bug reports appreciated. + +## Source Code + +Most sample source code is included from the project. They build without alteration and should be a good starting point for further explorations. The header files for the included library modules are in the INC directory. + +## Video Playlist + +There is a [YouTube playlist](https://www.youtube.com/playlist?list=PLlPKgUMQbJ79VJvZRfv1CJQf4SP2Gw3yU) created for learning PLASMA. It is a WIP, with updates every week or so + +## Issues + +- All the modules and runtime are written mostly in PLASMA; the compiler and editor as well. This means that there may be some startup delay as the PLASMA module loader reads in the module dependencies and performs dynamic linking. But a 1 MHz, 8 bit CPU interpreting bytecodes is never going to match a modern computer. As noted earlier, an accelerator and mass storage are your (and PLASMA's) friend. + +- All the project modules are included. They have been lightly tested. + +- The Apple /// may not always report errors properly or at all. + +- The documentation is sparse and incomplete. Yep, could use your help... + +# Changes in PLASMA for 2.0 DP 3 + +1. File manipulation utilities fixed for Apple /// SOS vs ProDOS differences + +2. More optimizations for HiRes graphics libraries + +3. Spiders From Mars hires demo game + +# Changes in PLASMA for 2.0 DP 2 + +1. Many file manipulaition utilities (COPY, REName, NEWDIRectory, DELete, CATalog, TYPE) + +2. New and updated libraries for lo-res. double lo-res and hi-res graphics w/ sprites + +3. 32 bit integer library for those times when 16 bits just isn't enough + +4. Apple /// improvements to other SOS.INTERP launching with SOS utility + +5. Apple /// JIT VM for speed and non JIT version to free up global memory + +6. Editor improvements + +7. A couple small compiler optimizations + +8. Needed to break out TCP/IP modules into seperate floppy image + +9. Library changes require full install + +# Changes in PLASMA for 2.0 DP 1z + +1. Many fixes for the value zero - especially in 65802/65816 divide routine + +# Changes in PLASMA for 2.0 DP 1 E+C + +1. Greatly improved code editor and additional compiler stats + +# Changes in PLASMA for 2.0 DP 1a + +1. Fix interaction with JIT compiler and module load/unload + +# Changes in PLASMA for 2.0 DP 1 + +1. Expanded bytecode for more efficient size/performance of programs + +2. Just-In-Time Compiler for native code performance (6502 and 65816) for frequently called routines + +3. Automatically identify and run most optimal VM for configuration + +# Changes in PLASMA for 1.2 + +1. Add TFTPD TFTP server + +2. Fix Uthernet 1 driver + +3. Add mouse module + +4. Fix IRQ issues for interrupt driven mouse driver + +# Changes in PLASMA for 1.1 + +1. All known bugs are fixed + +2. PLASM compiler received a little performance boost with an assembly language helper for ID/keyword lexical scanner + +# Changes in PLASMA for 1.0 + +If you have been programming in PLASMA before, the 1.0 version has some major and minor changes that you should be aware of: + +1. Case is no longer significant. Imported symbols were always upper case. Now, all symbols are treated as if they were upper case. You may find that some symbols clash with previously defined symbols of different case. Hey, we didn't need lower case in 1977 and we don't need it now. You kids, get off my lawn! + +2. Modules are now first class citizens. Translation: importing a module adds a symbol with the module name. You can simply refer to a module's address with it's name. This is how a module's API table is accessed (instead of adding a variable of the same name in the IMPORT section). + +3. Bytecode changes means previously compiled modules will crash. Rebuild. + +4. `BYTE` and `WORD` have aliases that may improve readability of the code. `CHAR` (character) and `RES` (reserve) are synonyms for `BYTE`. `VAR` (variable) is a synonym for `WORD`. These aliases add no functionality. They are simply syntactic sugar to add context to the source code, but may cause problems if you've previously used the same names for identifiers. + +5. When declaring variables, a base size can come after the type, and an array size can folllow the identifier. For instance: +``` +res[10] a, b, c +``` +will reserve three variables of 10 bytes each. Additionally: +``` +res[10] v[5], w[3] +``` +will reserve a total of 80 bytes (10 * 5 + 10 * 3). This would be useful when combined with a structure definition. One could: +``` +res[t_record] patients[20] +``` +to reserve an array of 20 patient records. + +6. Ternary operator. Just like C and descendants, `??` and `::` allow for an if-then-else inside an expression: +``` +puts(truth == TRUE ?? "TRUE" :: "FALSE") +``` + +7. Multiple value assignements. Multiple values can be returned from functions and listed on variable assignments: +``` +def func#3 // Return 3 values + return 10, 20, 30 +end + +a, b, c = 1, 2, 3 +c, d, f = func() +x, y = y, x // Swap x and y +``` + +8. `DROP` allows for explicit dropping of values. In the above `func()` example, if the middle value was the only one desired, the others can be ignored with: +``` +drop, h, drop = func() +``` + +9. The compiler tracks parameter and return counts for functions. If the above `func()` were used without assigning all the return values, they would be dropped: +``` +a = func() // Two values silently dropped +``` +To generate compiler warning for this issue, and a few others, use the `-W` option when compiling. + +10. Lambda (Anonymous) Functions. The ability to code a quick function in-line can be very powerful when used properly. Look here, https://en.wikipedia.org/wiki/Anonymous_function, for more information. + +11. SANE (Standard Apple Numerics Environment) Floating Point Library. An extensive library (two, actually) of extended floating point (80 bit IEEE precision) functionality is suported. A wrapper library has been written to greatly simplify the interface to SANE. Look at the `RPNCALC.PLA` source code as an example. + +12. Library Documentation. Preliminary documentation is available on the Wiki: https://github.com/dschmenk/PLASMA/wiki + +13. Significant effort has gone into VM tuning and speeding up module loading/dynamic linking. + +14. The VM zero page usage has changed. If you write assembly language routines, you will need to rebuild. + +# Thanks + +I wish to thank the people who have contributed the the PLASMA project. They have greatly improved the development of the language and documentation: + +- Martin Haye: PLASMA programmer extraordinaire. Mr. Lawless Legends has requested many of the crucial features that set PLASMA apart. +- Steve F (ZornsLemma): Has taken the optimizer to new levels and his work on porting PLASMA to the Beeb are amazing: http://stardot.org.uk/forums/viewtopic.php?f=55&t=12306&sid=5a503c593f0698ebc31e590ac61b09fc +- Peter Ferrie: Assembly optimizer extraordinaire. He has made significant improvements into the code footprint in PLASMA so all the functionality can exist in just a few bytes. +- David Schmidt (DaveX): His help in documentation have made it much more accessible and professional. Of course any errors are all his. Just kidding, they're mine ;-) +- Andy Werner (6502.org): Catching the grammatical errors that I ain't no good at. +- John Brooks: Apple II Guru par excellence. His insights got 10% performance increase out of the VM. + +Dave Schmenk +http://schmenk.is-a-geek.com diff --git a/images/apple/PLASMA-BLD2.PO b/images/apple/PLASMA-BLD2.PO deleted file mode 100644 index 5c06ff0..0000000 Binary files a/images/apple/PLASMA-BLD2.PO and /dev/null differ diff --git a/images/apple/PLASMA2-BLD.PO b/images/apple/PLASMA2-BLD.PO new file mode 100644 index 0000000..2b2513d Binary files /dev/null and b/images/apple/PLASMA2-BLD.PO differ diff --git a/images/apple/PLASMA2-DEM.PO b/images/apple/PLASMA2-DEM.PO new file mode 100644 index 0000000..b440a67 Binary files /dev/null and b/images/apple/PLASMA2-DEM.PO differ diff --git a/images/apple/PLASMA-FPSOS.PO b/images/apple/PLASMA2-FPSOS.PO similarity index 82% rename from images/apple/PLASMA-FPSOS.PO rename to images/apple/PLASMA2-FPSOS.PO index cf84e21..372aff4 100644 Binary files a/images/apple/PLASMA-FPSOS.PO and b/images/apple/PLASMA2-FPSOS.PO differ diff --git a/images/apple/PLASMA-DEM2.PO b/images/apple/PLASMA2-INET.PO similarity index 83% rename from images/apple/PLASMA-DEM2.PO rename to images/apple/PLASMA2-INET.PO index de3ceeb..ce7e561 100644 Binary files a/images/apple/PLASMA-DEM2.PO and b/images/apple/PLASMA2-INET.PO differ diff --git a/images/apple/PLASMA-SYS2.PO b/images/apple/PLASMA2-SYS.PO similarity index 52% rename from images/apple/PLASMA-SYS2.PO rename to images/apple/PLASMA2-SYS.PO index 7667177..9a1f3bc 100755 Binary files a/images/apple/PLASMA-SYS2.PO and b/images/apple/PLASMA2-SYS.PO differ diff --git a/images/apple/PLASMA.2mg b/images/apple/PLASMA2.2mg similarity index 62% rename from images/apple/PLASMA.2mg rename to images/apple/PLASMA2.2mg index 51f1a3c..c9106af 100644 Binary files a/images/apple/PLASMA.2mg and b/images/apple/PLASMA2.2mg differ diff --git a/images/apple/SFM.PO b/images/apple/SFM.PO new file mode 100644 index 0000000..097c2e7 Binary files /dev/null and b/images/apple/SFM.PO differ diff --git a/images/apple/TFTPD.PO b/images/apple/TFTPD.PO new file mode 100644 index 0000000..6c00083 Binary files /dev/null and b/images/apple/TFTPD.PO differ diff --git a/src/inc/dgr.plh b/src/inc/dgr.plh deleted file mode 100644 index 0449a16..0000000 --- a/src/inc/dgr.plh +++ /dev/null @@ -1,16 +0,0 @@ -import dgr - word[] dgrbuff - predef dgrPlot(buff, x, y)#0 - predef dgrHLin(buff, x1, x2, y)#0 - predef dgrVLin(buff, x, y1, y2)#0 - predef dgrBLT(buff, x, y, width, height, src)#0 - predef dgrTile(buff, x, y, src)#0 - predef dgrTileStr(buff, x, y, tilestr, strlen, tilebuff)#0 - predef dgrFill(buff, x, y, tile)#0 - predef dgrMode#1 - predef txtMode#0 - predef dgrShow(page)#1 - predef dgrColor(clr)#0 - predef dgrLine(buff, x1, y1, x2, y2)#0 - predef dgrClear(buff, clr)#0 -end diff --git a/src/inc/dgrlib.plh b/src/inc/dgrlib.plh new file mode 100644 index 0000000..7904afc --- /dev/null +++ b/src/inc/dgrlib.plh @@ -0,0 +1,15 @@ +import dgrlib + predef dgrPlot(x, y)#0 + predef dgrHLin(x1, x2, y)#0 + predef dgrVLin(y1, y2, x)#0 + predef dgrBLT(x, y, width, height, src)#0 + predef dgrTile(x, y, src)#0 + predef dgrTileStr(x, y, tilestr, strlen, tilebuff)#0 + predef dgrFill(x, y, tile)#0 + predef dgrClear(clr)#0 + predef dgrMode(mode)#1 + predef dgrShow(page)#1 + predef dgrSwap#0 + predef dgrDrawBuf(page)#0 + predef dgrColor(clr)#0 +end diff --git a/src/inc/fileio.plh b/src/inc/fileio.plh index 699a514..4226cf1 100644 --- a/src/inc/fileio.plh +++ b/src/inc/fileio.plh @@ -18,7 +18,27 @@ import fileio const FILE_ERR_INT_TBL_FULL = $25 const FILE_ERR_IO = $27 // + // File entry struc + // + struc t_fileentry + byte store_namelen + byte entry_name[15] + byte entry_type + word entry_keyptr + word entry_blocks + word entry_EOFL + byte entry_EOFH + word entry_create[2] + byte entry_version + byte entry_minver + byte entry_access + word entry_aux + word entry_mod[2] + word entry_headptr + end + // // File info struc + // struc t_fileinfo byte file_access byte file_type @@ -37,7 +57,9 @@ import fileio word getpfx word setpfx word getfileinfo + word setfileinfo word geteof + word seteof word iobufalloc word open word close @@ -45,7 +67,9 @@ import fileio word write word create word destroy + word rename word newline + word online word readblock word writeblock end diff --git a/src/inc/grlib.plh b/src/inc/grlib.plh new file mode 100644 index 0000000..f1aa61f --- /dev/null +++ b/src/inc/grlib.plh @@ -0,0 +1,15 @@ +import grlib + predef grPlot(x, y)#0 + predef grHLin(x1, x2, y)#0 + predef grVLin(y1, y2, x)#0 + predef grBLT(x, y, width, height, src)#0 + predef grTile(x, y, src)#0 + predef grTileStr(x, y, tilestr, strlen, tilebuff)#0 + predef grFill(x, y, tile)#0 + predef grClear(clr)#0 + predef grMode(mode)#1 + predef grShow(page)#1 + predef grSwap#0 + predef grDrawBuf(page)#0 + predef grColor(clr)#0 +end diff --git a/src/inc/hgrfont.plh b/src/inc/hgrfont.plh new file mode 100644 index 0000000..93c069c --- /dev/null +++ b/src/inc/hgrfont.plh @@ -0,0 +1,3 @@ +import hgrfont + predef hgrPutStr(x, y, strptr)#0 +end diff --git a/src/inc/hgrlib.plh b/src/inc/hgrlib.plh new file mode 100644 index 0000000..251fcf1 --- /dev/null +++ b/src/inc/hgrlib.plh @@ -0,0 +1,24 @@ +import hgrlib + predef divmod7(x)#2 + predef hgrPlot(x, y)#0 + predef hgrOrPlot(x, y)#0 + predef hgrXorPlot(x, y)#0 + predef hgrHLin(x1, x2, y)#0 + predef hgrVLin(y1, y2, x)#0 + predef hgrXorHLin(x1, x2, y)#0 + predef hgrXorVLin(y1, y2, x)#0 + predef hgrRect(x1, y1, x2, y2)#0 + predef hgrXorRect(x1, y1, x2, y2)#0 + predef hgrBLT(x, y, width, height, srcptr)#0 + predef hgrCopySrc(ofst, y, w, h, srcptr)#0 + predef hgrAndSrc(ofst, y, w, h, srcptr)#0 + predef hgrXorSrc(ofst, y, w, h, srcptr)#0 + predef hgrOrSrc(ofst, y, w, h, srcptr)#0 + predef hgrCopyDst(ofst, y, w, h, dstptr)#0 + predef hgrMode(mode)#1 + predef hgrClear#0 + predef hgrShow(page)#1 + predef hgrSwap#1 + predef hgrDrawBuf(page)#1 + predef hgrColor(clr)#0 +end diff --git a/src/inc/hgrsprite.plh b/src/inc/hgrsprite.plh new file mode 100644 index 0000000..eeaa4db --- /dev/null +++ b/src/inc/hgrsprite.plh @@ -0,0 +1,19 @@ +import hgrsprite + predef spriteCompile(w, h, xcenter, ycenter, srcptr)#1 + predef spriteDup(sprtsrc)#1 + predef spriteRead(filestr)#1 + predef spriteSave(filestr, sprtptr)#1 + predef spriteDraw(sprtptr)#0 + predef spriteDrawXor(sprtptr)#0 + predef spriteUnDraw(sprtptr)#0 + predef spriteUnDrawXor(sprtptr)#0 + predef spritePos(x, y, sprtptr)#0 + predef spritePosIndex(x, y, i)#0 + predef spriteUnDrawList#0 + predef spriteUnDrawXorList#0 + predef spriteDrawList#0 + predef spriteDrawXorList#0 + predef spriteAdd(i, sprtptr)#1 + predef spriteDel(i)#1 + predef spriteDrawBuf(page)#1 +end diff --git a/src/inc/hgrtile.plh b/src/inc/hgrtile.plh new file mode 100644 index 0000000..9a8bac9 --- /dev/null +++ b/src/inc/hgrtile.plh @@ -0,0 +1,13 @@ +import hgrtile + predef tileDraw(x, y, tileptr)#0 + predef tileXorDraw(x, y, tileptr)#0 + predef tileOrDraw(x, y, tileptr)#0 + predef tileAndDraw(x, y, tileptr)#0 + predef tileDrawStr(x, y, strptr, strlen, tileset)#0 + predef tileFromText(txtpage, tileset)#0 + predef tileMode(mode)#1 + predef tileClear#0 + predef tileShow(page)#1 + predef tileSwap#1 + predef tileDrawBuf(page)#1 +end diff --git a/src/inc/int32.plh b/src/inc/int32.plh new file mode 100644 index 0000000..13e0096 --- /dev/null +++ b/src/inc/int32.plh @@ -0,0 +1,32 @@ +import int32 + const t_i32 = 4 + + predef zero32#0 + predef zext16to32#0 + predef neg32#0 + predef load32(i32ptr)#0 + predef loadi16(imm16)#0 + predef store32(i32ptr)#0 + predef add32(i32ptr)#0 + predef addi16(imm16)#0 + predef sub32(i32ptr)#0 + predef subi16(imm16)#0 + predef shl32(imm8)#0 + predef shr32(imm8)#0 + predef mul32(i32ptr)#0 + predef muli16(imm16)#0 + predef div32(i32ptr)#2 + predef divi16(imm16)#2 + predef iseq32(i32ptr)#1 + predef iseqi16(imm16)#1 + predef isge32(i32ptr)#1 + predef isgei16(imm16)#1 + predef isle32(i32ptr)#1 + predef islei16(imm16)#1 + predef isgt32(i32ptr)#1 + predef isgti16(imm16)#1 + predef islt32(i32ptr)#1 + predef islti16(imm16)#1 + predef i32tos(i32ptr, strptr)#1 + predef puti32(i32ptr)#0 +end diff --git a/src/inc/lines.plh b/src/inc/lines.plh new file mode 100644 index 0000000..b9afda4 --- /dev/null +++ b/src/inc/lines.plh @@ -0,0 +1,6 @@ +import lines + predef setlinespans(h, v)#0 + predef linespans(x1, y1, x2, y2)#0 + predef setlineplot(p)#0 + predef line(x1, y1, x2, y2)#0 +end diff --git a/src/inc/matchfiles.plh b/src/inc/matchfiles.plh new file mode 100644 index 0000000..9c571d4 --- /dev/null +++ b/src/inc/matchfiles.plh @@ -0,0 +1,5 @@ +import matchfiles + predef matchName(src, exp)#1 + predef matchList(pathptr, exp)#2 + predef isWildName(exp)#1 +end diff --git a/src/libsrc/apple/dgr.pla b/src/libsrc/apple/dgrlib.pla similarity index 71% rename from src/libsrc/apple/dgr.pla rename to src/libsrc/apple/dgrlib.pla index d76d49e..69302b0 100755 --- a/src/libsrc/apple/dgr.pla +++ b/src/libsrc/apple/dgrlib.pla @@ -1,5 +1,4 @@ include "inc/cmdsys.plh" -sysflags restxt1|restxt2|resxtxt1|resxtxt2 // Reserve all text pages // // Apple II hardware constants. // @@ -24,13 +23,15 @@ const page2 = 1 // // Screen row address arrays. // -word[] dgr1rows = $0400,$0480,$0500,$0580,$0600,$0680,$0700,$0780 -word = $0428,$04A8,$0528,$05A8,$0628,$06A8,$0728,$07A8 -word = $0450,$04D0,$0550,$05D0,$0650,$06D0,$0750,$07D0 -word[] dgr2rows = $0800,$0880,$0900,$0980,$0A00,$0A80,$0B00,$0B80 -word = $0828,$08A8,$0928,$09A8,$0A28,$0AA8,$0B28,$0BA8 -word = $0850,$08D0,$0950,$09D0,$0A50,$0AD0,$0B50,$0BD0 -export word[] dgrbuff = @dgr1rows, @dgr2rows +word[] dgr1row = $0400,$0480,$0500,$0580,$0600,$0680,$0700,$0780 +word = $0428,$04A8,$0528,$05A8,$0628,$06A8,$0728,$07A8 +word = $0450,$04D0,$0550,$05D0,$0650,$06D0,$0750,$07D0 +word[] dgr2row = $0800,$0880,$0900,$0980,$0A00,$0A80,$0B00,$0B80 +word = $0828,$08A8,$0928,$09A8,$0A28,$0AA8,$0B28,$0BA8 +word = $0850,$08D0,$0950,$09D0,$0A50,$0AD0,$0B50,$0BD0 +word[] dgrbuff = @dgr1row, @dgr2row +word drawbuff +byte drawpage // // Color mapping. // @@ -49,13 +50,13 @@ end // // Plot pixel // -export asm dgrPlot(buff, x, y)#0 - ; GET BUFFER ADDRESS - STX ESP - LDA ESTKL+2,X +export asm dgrPlot(x, y)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 STA SRCL - LDA ESTKH+2,X - STA SRCH + LDA $3001 + STA SRCH + STX ESP LDA ESTKL,X ; Y COORD AND #$FE TAY @@ -76,22 +77,21 @@ asm _dgrPlotPix LDX ESP INX INX - INX RTS end // // Plot horizontal row of pixels // -export asm dgrHLin(buff, x1, x2, y)#0 - ; GET BUFFER ADDRESS - STX ESP - LDA ESTKL+3,X +export asm dgrHLin(x1, x2, y)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 STA SRCL - LDA ESTKH+3,X - STA SRCH + LDA $3001 + STA SRCH + STX ESP LDA ESTKL+1,X ; X2 COORD STA TMPH - LDA ESTKL,X ; Y COORD + LDA ESTKL+0,X ; Y COORD AND #$FE TAY LDA (SRC),Y @@ -102,7 +102,7 @@ export asm dgrHLin(buff, x1, x2, y)#0 LDY ESTKL+2,X ; X1 COORD PHP SEI -- LDA ESTKL,X +- LDA ESTKL+0,X ; Y COORD LSR TYA LDX GCLR ; COLOR @@ -119,20 +119,19 @@ asm _dgrHLinPix INX INX INX - INX RTS end // // Plot horizontal row of pixels // -export asm dgrVLin(buff, x, y1, y2)#0 - ; GET BUFFER ADDRESS - STX ESP - LDA ESTKL+3,X +export asm dgrVLin(y1, y2, x)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 STA SRCL - LDA ESTKH+3,X - STA SRCH - LDA ESTKL+1,X ; Y1 COORD + LDA $3001 + STA SRCH + STX ESP + LDA ESTKL+2,X ; Y1 COORD PHP SEI - AND #$FE @@ -142,38 +141,38 @@ export asm dgrVLin(buff, x, y1, y2)#0 INY LDA (SRC),Y STA GBASH - LDA ESTKL+1,X + LDA ESTKL+2,X LSR - LDA ESTKL+2,X ; X COORD + LDA ESTKL+0,X ; X COORD LDX GCLR ; COLOR end asm _dgrVLinPix JSR $3000 ; _dgrSetPix LDX ESP - INC ESTKL+1,X ; Y1 COORD - LDA ESTKL+1,X - CMP ESTKL,X ; Y2 COORD + INC ESTKL+2,X ; Y1 COORD + LDA ESTKL+2,X + CMP ESTKL+1,X ; Y2 COORD BCC - BEQ - PLP INX INX INX - INX RTS end // // Draw sprite // -export asm dgrBLT(buff, x, y, width, height, src)#0 +export asm dgrBLT(x, y, width, height, src)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 + STA DSTL + LDA $3001 + STA DSTH LDA ESTKL,X ; SPRITE STA SRCL LDA ESTKH,X STA SRCH - LDA ESTKL+5,X - STA DSTL - LDA ESTKH+5,X - STA DSTH LDA ESTKL+4,X ; X1 COORD CMP #80 BPL ++++ @@ -197,9 +196,8 @@ export asm dgrBLT(buff, x, y, width, height, src)#0 CLC ADC ESTKL+2,X ; WIDTH STA SRCL - LDA SRCH - ADC #$00 - STA SRCH + BCC +++ + INC SRCH BNE +++ + AND #$FE TAY @@ -245,7 +243,6 @@ asm _dgrBLTPix INX INX INX - INX RTS end // @@ -326,16 +323,17 @@ end // // Draw 8x8 tile (forced to 2x2 block address) // -export asm dgrTile(buff, x, y, src)#0 +export asm dgrTile(x, y, src)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 + STA DSTL + LDA $3001 + STA DSTH STX ESP LDA ESTKL,X ; TILE STA SRCL LDA ESTKH,X STA SRCH - LDA ESTKL+3,X - STA DSTL - LDA ESTKH+3,X - STA DSTH LDA ESTKL+2,X ; X1 COORD CMP #80 BPL ++++ @@ -357,9 +355,8 @@ export asm dgrTile(buff, x, y, src)#0 LDA SRCL ; SKIP TO NEXT ROW ADC #$07 ; CARRY = 1 STA SRCL - LDA SRCH - ADC #$00 - STA SRCH + BCC +++ + INC SRCH BNE +++ + AND #$FE TAY @@ -392,9 +389,9 @@ export asm dgrTile(buff, x, y, src)#0 STA (GBASE),Y ++ INC TMPH ; X COORD INC TMPH ; X COORD - LDX ESP LDA TMPH BMI -- + LDX ESP CMP ESTKH+2,X ; X2 COORD BCC -- PLP @@ -405,7 +402,6 @@ export asm dgrTile(buff, x, y, src)#0 CMP ESTKH+1,X ; Y2 COORD BCC - ++++ INX - INX INX INX RTS @@ -413,22 +409,17 @@ end // // Draw a string of tiles // -export asm dgrTileStr(buff, x, y, tilestr, strlen, tilebuff)#0 +export asm dgrTileStr(x, y, tilestr, strlen, tilebuff)#0 - DEX DEX DEX - DEX - LDA ESTKL+9,X ; BUFF - STA ESTKL+3,X - LDA ESTKH+9,X - STA ESTKH+3,X - LDA ESTKL+8,X ; X COORD + LDA ESTKL+7,X ; X COORD STA ESTKL+2,X - LDA ESTKL+7,X ; Y COORD + LDA ESTKL+6,X ; Y COORD STA ESTKL+1,X - LDA ESTKL+4,X ; TILE + LDA ESTKL+3,X ; TILE STA ESTKL,X - LDA ESTKH+4,X ; TILE + LDA ESTKH+3,X ; TILE STA ESTKH,X end asm _dgrTileTile @@ -441,16 +432,17 @@ asm _dgrTileTile STA ESTKL+4,X DEC ESTKL+1,X ; DEC STRLEN BNE - -+ TXA - CLC - ADC #6 - TAX ++ INX + INX + INX + INX + INX RTS end // // Fill a buffer with tiles // -export asm dgrFill(buff, x, y, tile)#0 +export asm dgrFill(x, y, tile)#0 LDA ESTKL+2,X AND #$0F STA ESTKL+2,X @@ -469,18 +461,13 @@ export asm dgrFill(buff, x, y, tile)#0 - DEX DEX DEX - DEX - LDA ESTKL+7,X ; BUFF - STA ESTKL+3,X - LDA ESTKH+7,X - STA ESTKH+3,X - LDA ESTKL+6,X ; X COORD + LDA ESTKL+5,X ; X COORD STA ESTKL+2,X - LDA ESTKL+5,X ; Y COORD + LDA ESTKL+4,X ; Y COORD STA ESTKL+1,X - LDA ESTKL+4,X ; TILE + LDA ESTKL+3,X ; TILE STA ESTKL,X - LDA ESTKH+4,X ; TILE + LDA ESTKH+3,X ; TILE STA ESTKH,X end asm _dgrFillTile @@ -502,11 +489,10 @@ asm _dgrFillTile INX INX INX - INX RTS end // -// Wait for VLB - Shouldn't work on //c, but seems to. +// Wait for VLB - Only IIe/IIGS. // asm vlbWait#0 - LDA $C019 @@ -515,23 +501,59 @@ asm vlbWait#0 BPL - RTS end +// Wait for VBL on IIc is entirely different from others. +// Setup, one-time *only* if polling will be used exclusively. +// Otherwise requires restoring the mode on exit, +// and setting up per-use instead. +// [php] +// sei ; otherwise interrupt is still raised +// sta $C07F ; enable access to VBL register +// sta $C05B ; enable VBL polling +// sta $C07E ; disable access to VBL register // -// Set double lores graphics, return draw buffer +// wait for VBL: +// - bit $C019 +// bpl - +// lda $C070 ; $c019 bit 7 is sticky, reset it // -export def dgrMode#1 - ^showlores - ^showfull - ^showgraphics - ^showpage1 - ^ena80 = 0 - ^show80 = 0 - ^an3on - return 1 +// To allow other methods of VBL, restore access: +// - bit $C019 +// bpl - +// lda $C070 ; $c019 bit 7 is sticky, reset it +// sta $C07F ; enable access to VBL register +// sta $C05A ; disable VBL polling +// sta $C07E ; disable access to VBL register +// [plp] + +// +// Clear the buffer +// +export def dgrClear(clr)#0 + byte[32] clrtile + + clr = evnclr[clr&$0F] | (oddclr[clr&$0F] << 8) + memset(@clrtile, clr, 32) + dgrFill(0, 0, @clrtile) end -// -// Set text mode -// -export def txtMode#0 +export def dgrMode(mode)#1 + if mode + // + // Set double lores graphics, return draw buffer + // + ^showlores + ^showfull + ^showgraphics + ^showpage1 + ^ena80 = 0 + ^show80 = 0 + ^an3on + drawpage = 1 + drawbuff = dgrbuff[1] + return 1 + fin + // + // Set text mode + // ^showtext ^showpage1 ^ena80 = 0 @@ -539,6 +561,7 @@ export def txtMode#0 ^mapmain = 0 ^an3off call($FC58, 0, 0, 0, 0) // home() + return 0 end // // Set display page, return other page @@ -548,6 +571,15 @@ export def dgrShow(page)#1 ^(showpage1 + page) return page ^ 1 end +export def dgrSwap#0 + ^(showpage1 + drawpage) + drawpage = drawpage ^ 1 + drawbuff = dgrbuff[drawpage] +end +export def dgrDrawBuf(page)#0 + drawpage = page + drawbuff = dgrbuff[drawpage] +end // // Set color for clear & plot routines // @@ -555,91 +587,6 @@ export def dgrColor(clr)#0 ^$30 = clr & $0F end // -// Draw line -// -export def dgrLine(buff, x1, y1, x2, y2)#0 - byte dx, dy, dx2, dy2, pp - word sx, sy, err, dd2 - - if x1 < x2 - sx = 1 - dx = x2 - x1 - else - sx = -1 - dx = x1 - x2 - fin - if y1 < y2 - sy = 1 - dy = y2 - y1 - else - sy = -1 - dy = y1 - y2 - fin - dx2 = dx << 1 - dy2 = dy << 1 - if dx >= dy // Horizontal line - if sx < 0 - x1, x2 = x2, x1 - y1, y2 = y2, y1 - sy = -sy - fin - dd2 = dx2 - dy2 - err = dx - dy2 - sx = 1 - while dy - if err < 0 - dgrHLin(buff, x1, x1 + sx - 1, y1) - x1 = x1 + sx - y1 = y1 + sy - sx = 1 - dy-- - err = err + dd2 - else - sx++ - err = err - dy2 - fin - loop - if y2 == y1 - dgrHLin(buff, x1, x2, y1) - fin - else // Vertical line - if sy < 0 - x1, x2 = x2, x1 - y1, y2 = y2, y1 - sx = -sx - fin - dd2 = dy2 - dx2 - err = dy - dx2 - sy = 1 - while dx - if err < 0 - dgrVLin(buff, x1, y1, y1 + sy - 1) - x1 = x1 + sx - y1 = y1 + sy - sy = 1 - dx-- - err = err + dd2 - else - sy++ - err = err - dx2 - fin - loop - if x2 == x1 - dgrVLin(buff, x1, y1, y2) - fin - fin -end -// -// Clear the buffer -// -export def dgrClear(buff, clr)#0 - byte[32] clrtile - - clr = evnclr[clr&$0F] | (oddclr[clr&$0F] << 8) - memset(@clrtile, clr, 32) - dgrFill(buff, 0, 0, @clrtile) -end -// // Make sure we are a 128K //e or //c // if MACHID & $F0 <> $B0 @@ -661,6 +608,19 @@ _dgrSetEvnEvn:1 = @evnclr _dgrSetEvnOdd:1 = @oddclr _dgrSetOddEvn:1 = @evnclr _dgrSetOddOdd:1 = @oddclr +// +// Fixups for drawbuff +// +dgrPlot:1 = @drawbuff +dgrPlot:6 = @drawbuff+1 +dgrHLin:1 = @drawbuff +dgrHLin:6 = @drawbuff+1 +dgrVLin:1 = @drawbuff +dgrVLin:6 = @drawbuff+1 +dgrBLT:1 = @drawbuff +dgrBLT:6 = @drawbuff+1 +dgrTile:1 = @drawbuff +dgrTile:6 = @drawbuff+1 // Put read AUX mem routine in scary location memcpy($0100, @auxRead, 9) done diff --git a/src/libsrc/apple/fileio.pla b/src/libsrc/apple/fileio.pla index db299a2..0020808 100644 --- a/src/libsrc/apple/fileio.pla +++ b/src/libsrc/apple/fileio.pla @@ -26,7 +26,9 @@ struc t_fileio word getpfx word setpfx word getfileinfo + word setfileinfo word geteof + word seteof word iobufalloc word open word close @@ -34,20 +36,22 @@ struc t_fileio word write word create word destroy + word rename word newline + word online word readblock word writeblock end -predef a2getpfx(path), a23setpfx(path), a2getfileinfo(path, fileinfo), a23geteof(refnum), a2iobufs(iobufs), a2open(path), a2close(refnum) -predef a23read(refnum, buf, len), a2write(refnum, buf, len), a2create(path, type, aux), a23destroy(path) -predef a2newline(refnum, emask, nlchar), a2readblock(unit, buf, block), a2writeblock(unit, buf, block) +predef a2getpfx(path), a23setpfx(path), a2getfileinfo(path, fileinfo), a2setfileinfo(path, fileinfo), a23geteof(refnum)#2, a23seteof(refnum, eofl, eofh), a2iobufs(iobufs), a2open(path), a2close(refnum) +predef a23read(refnum, buf, len), a2write(refnum, buf, len), a2create(path, type, aux), a23destroy(path), a23rename(path, newpath) +predef a2newline(refnum, emask, nlchar), a2online(unit, buf), a2readblock(unit, buf, block), a2writeblock(unit, buf, block) // // Exported function table. // word fileio[] -word = @a2getpfx, @a23setpfx, @a2getfileinfo, @a23geteof, @a2iobufs, @a2open, @a2close -word = @a23read, @a2write, @a2create, @a23destroy -word = @a2newline, @a2readblock, @a2writeblock +word = @a2getpfx, @a23setpfx, @a2getfileinfo, @a2setfileinfo, @a23geteof, @a23seteof, @a2iobufs, @a2open, @a2close +word = @a23read, @a2write, @a2create, @a23destroy, @a23rename +word = @a2newline, @a2online, @a2readblock, @a2writeblock // // SOS/ProDOS error code // @@ -117,17 +121,53 @@ def a3getfileinfo(path, fileinfo) perr = syscall($C4, @params) return perr end -def a1geteof(refnum) - return 0 +def a1setfileinfo(path, fileinfo) + perr = $01 + return perr end -def a23geteof(refnum) +def a2setfileinfo(path, fileinfo) + byte params[14] + + params.0 = 7 + params:1 = path + memcpy(@params + 3, fileinfo, 11) + perr = syscall($C3, @params) + return perr +end +def a3setfileinfo(path, fileinfo) byte params[6] + params.0 = 3 + params:1 = path + params:3 = fileinfo + params.5 = 15 + perr = syscall($C3, @params) + return perr +end +def a1geteof(refnum)#2 + return 0, 0 +end +def a23geteof(refnum)#2 + byte params[5] + params.0 = 2 params.1 = refnum params:2 = 0 - params:4 = 0 + params.4 = 0 syscall($D1, @params) + return params:2, params.4 +end +def a1seteof(refnum, eofl, eofh) + return 0 +end +def a23seteof(refnum, eofl, eofh) + byte params[5] + + params.0 = 2 + params.1 = refnum + params:2 = eofl + params.4 = eofh + syscall($D0, @params) return params:2 end def a1open(path) @@ -258,7 +298,7 @@ def a3write(refnum, buff, len) params:2 = buff params:4 = len perr = syscall($CB, @params) - return perr + return perr ?? 0 :: len end def a1create(path, type, aux) return perr @@ -271,7 +311,7 @@ def a2create(path, type, aux) params.3 = $C3 params.4 = type params:5 = aux - params.7 = $1 + params.7 = type == $0F ?? $0D :: $01 params:8 = 0 params:10 = 0 perr = syscall($C0, @params) @@ -284,13 +324,15 @@ def a3create(path, type, aux) params.0 = 3 params:1 = path params:3 = @options - params.5 = 3 + params.5 = 4 options.0 = type options:1 = aux + options.3 = type == $0F ?? $0D :: $01 perr = syscall($C0, @params) return perr end def a1destroy(path) + perr = $01 return perr end def a23destroy(path) @@ -301,6 +343,19 @@ def a23destroy(path) perr = syscall($C1, @params) return perr end +def a1rename(oldpath, newpath) + perr = $01 + return perr +end +def a23rename(path, newpath) + byte params[5] + + params.0 = 2 + params:1 = path + params:3 = newpath + perr = syscall($C2, @params) + return perr +end def a1newline(refnum, emask, nlchar) return perr end @@ -324,6 +379,57 @@ def a3newline(refnum, emask, nlchar) perr = syscall($C9, @params) return perr end +def a1online(unit, buf) + perr = $27 // IOERR + return perr +end +def a2online(unit, buf) + byte params[4] + + params.0 = 2 + params.1 = unit + params:2 = buf + perr = syscall($C5, @params) + return perr +end +def a3volume(unit, volname) + byte devname[17] + byte info[11] + byte params[9] + + ^volname = 0 + params.0 = 4 + params.1 = unit + params:2 = @devname + params:4 = @info + params.6 = 11 + if syscall($85, @params) == 0 + params.0 = 4 + params:1 = @devname + params:3 = volname + params:5 = 0 + params:7 = 0 + return syscall($C5, @params) + fin + return -1 +end +def a3online(unit, buf) + byte info[11] + byte volname[17] + byte i + + if unit == 0 + for i = $01 to $0F + if a3volume(i, buf) == 0 + ^buf = ^buf | (i << 4) + fin + buf = buf + 16 + next + else + return a3volume(unit, buf) + fin + return 0 +end def a13readblock(unit, buf, block) perr = $27 // IOERR return perr @@ -359,12 +465,14 @@ when MACHID & MACHID_MODEL is MACHID_III fileio:getpfx = @a3getpfx fileio:getfileinfo = @a3getfileinfo + fileio:setfileinfo = @a3setfileinfo fileio:iobufalloc = @a13iobufs fileio:open = @a3open fileio:close = @a3close fileio:write = @a3write fileio:create = @a3create fileio:newline = @a3newline + fileio:online = @a3online fileio:readblock = @a13readblock fileio:writeblock = @a13writeblock break @@ -372,7 +480,9 @@ when MACHID & MACHID_MODEL fileio:getpfx = @a1getpfx fileio:setpfx = @a1setpfx fileio:getfileinfo = @a1getfileinfo + fileio:setfileinfo = @a1setfileinfo fileio:geteof = @a1geteof + fileio:seteof = @a1seteof fileio:iobufalloc = @a13iobufs fileio:open = @a1open fileio:close = @a1close @@ -380,7 +490,9 @@ when MACHID & MACHID_MODEL fileio:write = @a1write fileio:create = @a1create fileio:destroy = @a1destroy + fileio:rename = @a1rename fileio:newline = @a1newline + fileio:online = @a1online fileio:readblock = @a13readblock fileio:writeblock = @a13writeblock break diff --git a/src/libsrc/apple/grlib.pla b/src/libsrc/apple/grlib.pla new file mode 100644 index 0000000..163f14d --- /dev/null +++ b/src/libsrc/apple/grlib.pla @@ -0,0 +1,493 @@ +include "inc/cmdsys.plh" +// +// Apple II hardware constants. +// +const showgraphics = $C050 +const showtext = $C051 +const showfull = $C052 +const showmix = $C053 +const showpage1 = $C054 +const showpage2 = $C055 +const showlores = $C056 +const showhires = $C057 +const show40 = $C00C +const show80 = $C00D +const mapmain = $C000 +const mapaux = $C001 +const an3on = $C05E +const an3off = $C05F +const ena80 = $C07E +const dis80 = $C07F +const page1 = 0 +const page2 = 1 +// +// Screen row address arrays. +// +word[] gr1row = $0400,$0480,$0500,$0580,$0600,$0680,$0700,$0780 +word = $0428,$04A8,$0528,$05A8,$0628,$06A8,$0728,$07A8 +word = $0450,$04D0,$0550,$05D0,$0650,$06D0,$0750,$07D0 +word[] gr2row = $0800,$0880,$0900,$0980,$0A00,$0A80,$0B00,$0B80 +word = $0828,$08A8,$0928,$09A8,$0A28,$0AA8,$0B28,$0BA8 +word = $0850,$08D0,$0950,$09D0,$0A50,$0AD0,$0B50,$0BD0 +word[] grbuff = @gr1row, @gr2row +word drawbuff +byte drawpage + +asm grInc(buff) +!SOURCE "vmsrc/plvmzp.inc" +GBASL = $26 +GBASH = $27 +GBASE = GBASL +GCLR = $30 +end +// +// Plot pixel +// +export asm grPlot(x, y)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 + STA SRCL + LDA $3001 + STA SRCH + LDA ESTKL,X ; Y COORD + AND #$FE + TAY + LDA (SRC),Y + STA GBASL + INY + LDA (SRC),Y + STA GBASH + LDY ESTKL+1,X ; X COORD + LSR ESTKL,X + LDA GCLR ; COLOR + EOR (GBASE),Y + BCS + + ; EVEN ROW + AND #$0F + BCC ++ + ; ODD ROW ++ AND #$F0 +++ EOR (GBASE),Y + STA (GBASE),Y + INX + INX + RTS +end +// +// Plot horizontal row of pixels +// +export asm grHLin(x1, x2, y)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 + STA SRCL + LDA $3001 + STA SRCH + LDA ESTKL+1,X ; X2 COORD + STA TMPH + LDA ESTKL+0,X ; Y COORD + AND #$FE + TAY + LDA (SRC),Y + STA GBASL + INY + LDA (SRC),Y + STA GBASH + LDY ESTKL+2,X ; X1 COORD +- LDA ESTKL+0,X ; Y COORD + LSR + LDA GCLR ; COLOR + ; EVEN ROW + EOR (GBASE),Y + BCS + + AND #$0F + BCC ++ + ; ODD ROW ++ AND #$F0 +++ EOR (GBASE),Y + STA (GBASE),Y + INC ESTKL+2,X ; X1 COORD + LDY ESTKL+2,X + CPY TMPH ; X2 COORD + BCC - + BEQ - + INX + INX + INX + RTS +end +// +// Plot horizontal row of pixels +// +export asm grVLin(y1, y2, x)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 + STA SRCL + LDA $3001 + STA SRCH + LDA ESTKL+2,X ; Y1 COORD +- AND #$FE + TAY + LDA (SRC),Y + STA GBASL + INY + LDA (SRC),Y + STA GBASH + LDA ESTKL+2,X + LSR + LDY ESTKL+0,X ; X COORD + LDA GCLR ; COLOR + ; EVEN ROW + EOR (GBASE),Y + BCS + + AND #$0F + BCC ++ + ; ODD ROW ++ AND #$F0 +++ EOR (GBASE),Y + STA (GBASE),Y + INC ESTKL+2,X ; Y1 COORD + LDA ESTKL+2,X + CMP ESTKL+1,X ; Y2 COORD + BCC - + BEQ - + INX + INX + INX + RTS +end +// +// Draw sprite +// +export asm grBLT(x, y, width, height, src)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 + STA DSTL + LDA $3001 + STA DSTH + LDA ESTKL,X ; SPRITE + STA SRCL + LDA ESTKH,X + STA SRCH + LDA ESTKL+4,X ; X1 COORD + CMP #40 + BPL ++++ + CLC + ADC ESTKL+2,X + BMI ++++ + STA ESTKH+2,X ; X2 COORD + LDA ESTKL+3,X ; Y1 COORD + CMP #48 + BPL ++++ + STA ESTKH+3,X ; Y COORD + CLC + ADC ESTKL+1,X + BMI ++++ + STA ESTKH+1,X ; Y2 COORD + STX ESP + LDA ESTKH+3,X +- CMP #48 + BCC + + LDA SRCL ; SKIP TO NEXT ROW + CLC + ADC ESTKL+2,X ; WIDTH + STA SRCL + LDA SRCH + ADC #$00 + STA SRCH + BNE +++ ++ AND #$FE + TAY + LDA (DST),Y + STA GBASL + INY + LDA (DST),Y + STA GBASH + LDA ESTKL+4,X ; X1 COORD + STA ESTKH+4,X ; X COORD +-- CMP #40 + BCS ++ + STA TMP + LDA ESTKH+3,X ; Y COORD + LSR + LDY #$00 + LDA (SRC),Y + BMI ++ + LDY TMP + BCS oddBLT + ; EVEN ROW + EOR (GBASE),Y + AND #$0F + BCC evnBLT + ; ODD ROW +oddBLT ASL + ASL + ASL + ASL + EOR (GBASE),Y + AND #$F0 +evnBLT EOR (GBASE),Y + STA (GBASE),Y +++ INC SRCL + BNE + + INC SRCH ++ INC ESTKH+4,X ; X COORD + LDA ESTKH+4,X + BMI -- + CMP ESTKH+2,X ; X2 COORD + BCC -- ++++ INC ESTKH+3,X ; Y COORD + LDA ESTKH+3,X + BMI - + CMP ESTKH+1,X ; Y2 COORD + BCC - +++++ INX + INX + INX + INX + INX + RTS +end +// +// Draw 8x8 tile (forced to 1x2 block address) +// +export asm grTile(x, y, src)#0 + ; GET ROW BUFFER ADDRESSES + LDA $3000 + STA DSTL + LDA $3001 + STA DSTH + STX ESP + LDA ESTKL,X ; TILE + STA SRCL + LDA ESTKH,X + STA SRCH + LDA ESTKL+2,X ; X1 COORD + CMP #40 + BPL ++++ + CLC + ADC #$08 + BMI ++++ + STA ESTKH+2,X ; X2 COORD + LDA ESTKL+1,X ; Y1 COORD + CMP #48 + BPL ++++ + STA TMPL ; Y COORD + CLC + ADC #$08 + BMI ++++ + STA ESTKH+1,X ; Y2 COORD + LDA TMPL ; Y COORD +- CMP #48 + BCC + + LDA SRCL ; SKIP TO NEXT ROW + ADC #$07 ; CARRY = 1 + STA SRCL + LDA SRCH + ADC #$00 + STA SRCH + BNE +++ ++ AND #$FE + TAY + LDA (DST),Y + STA GBASL + INY + LDA (DST),Y + STA GBASH + LDA ESTKL+2,X ; X1 COORD + STA TMPH ; X COORD +-- TAY + CMP #40 + LDX #$00 + LDA (SRC,X) + INC SRCL + BNE + + INC SRCH ++ BCS ++ + STA (GBASE),Y +++ INC TMPH ; X COORD + LDA TMPH + BMI -- + LDX ESP + CMP ESTKH+2,X ; X2 COORD + BCC -- ++++ INC TMPL ; Y COORD + INC TMPL ; Y COORD + LDA TMPL + BMI - + CMP ESTKH+1,X ; Y2 COORD + BCC - +++++ INX + INX + INX + RTS +end +// +// Draw a string of tiles +// +export asm grTileStr(x, y, tilestr, strlen, tilebuff)#0 +- DEX + DEX + DEX + LDA ESTKL+7,X ; X COORD + STA ESTKL+2,X + LDA ESTKL+6,X ; Y COORD + STA ESTKL+1,X + LDA ESTKL+3,X ; TILE + STA ESTKL,X + LDA ESTKH+3,X ; TILE + STA ESTKH,X +end +asm _grTileTile + JSR $5000 + LDA ESTKL+4,X ; UPDATE X COORD + CLC + ADC #$08 + CMP #40 ; OFF RIGHT SIDE + BPL + + STA ESTKL+4,X + DEC ESTKL+1,X ; DEC STRLEN + BNE - ++ INX + INX + INX + INX + INX + RTS +end +// +// Fill a buffer with tiles +// +export asm grFill(x, y, tile)#0 + LDA ESTKL+2,X + AND #$0F + STA ESTKL+2,X + LDA ESTKL+1,X + AND #$0F + STA ESTKL+1,X + LDA #$00 + SEC + SBC ESTKL+2,X ; ORIGINAL X + STA ESTKL+2,X + STA ESTKH+2,X + LDA #$00 + SEC + SBC ESTKL+1,X + STA ESTKL+1,X +- DEX + DEX + DEX + LDA ESTKL+5,X ; X COORD + STA ESTKL+2,X + LDA ESTKL+4,X ; Y COORD + STA ESTKL+1,X + LDA ESTKL+3,X ; TILE + STA ESTKL,X + LDA ESTKH+3,X ; TILE + STA ESTKH,X +end +asm _grFillTile + JSR $5000 + LDA ESTKL+2,X ; UPDATE X COORD + CLC + ADC #$08 + STA ESTKL+2,X + CMP #40 ; OFF RIGHT SIDE? + BMI - + LDA ESTKH+2,X ; RESTORE X COORD + STA ESTKL+2,X + LDA ESTKL+1,X ; UPDATE Y COORD + CLC + ADC #$08 + STA ESTKL+1,X + CMP #48 ; OFF BOTTOM? + BMI - + INX + INX + INX + RTS +end +// +// Clear the buffer +// +export def grClear(clr)#0 + byte[32] clrtile + + clr = (clr & $0F) | (clr << 4) + clr = (clr & $FF) | (clr << 8) + memset(@clrtile, clr, 32) + grFill(0, 0, @clrtile) +end +// +// Set lores graphics, return draw buffer +// +export def grMode(mode)#1 + if mode + // + // Set GR mode + // + ^showlores + ^showfull + ^showgraphics + ^showpage1 + ^ena80 = 0 + ^show40 = 0 + ^mapmain = 0 + ^an3off + drawpage = 1 + drawbuff = grbuff[1] + return 1 + fin + // + // Set text mode + // + ^showtext + ^showpage1 + ^ena80 = 0 + ^show40 = 0 + ^mapmain = 0 + ^an3off + call($FC58, 0, 0, 0, 0) // home() + return 0 +end +// +// Set display page, return other page +// +export def grShow(page)#1 + page = page & 1 + ^(showpage1 + page) + return page ^ 1 +end +export def grSwap#0 + ^(showpage1 + drawpage) + drawpage = drawpage ^ 1 + drawbuff = grbuff[drawpage] +end +export def grDrawBuf(page)#0 + drawpage = page + drawbuff = grbuff[drawpage] +end +// +// Set color for clear & plot routines +// +export def grColor(clr)#0 + ^$30 = (clr & $0F) | (clr << 4) +end +// +// Assembly fixups +// +_grTileTile:1 = @grTile +_grFillTile:1 = @grTile +// +// Fixups for drawbuff +// +grPlot:1 = @drawbuff +grPlot:6 = @drawbuff+1 +grHLin:1 = @drawbuff +grHLin:6 = @drawbuff+1 +grVLin:1 = @drawbuff +grVLin:6 = @drawbuff+1 +grBLT:1 = @drawbuff +grBLT:6 = @drawbuff+1 +grTile:1 = @drawbuff +grTile:6 = @drawbuff+1 +done diff --git a/src/libsrc/apple/hgrfont.pla b/src/libsrc/apple/hgrfont.pla new file mode 100644 index 0000000..7bb06b6 --- /dev/null +++ b/src/libsrc/apple/hgrfont.pla @@ -0,0 +1,140 @@ +include "inc/hgrtile.plh" +// +// Apple //e hires character font +// +byte hgrFont[] +byte = $1C,$22,$2A,$3A,$1A,$02,$3C,$00,$08,$14,$22,$22,$3E,$22,$22,$00 +byte = $1E,$22,$22,$1E,$22,$22,$1E,$00,$1C,$22,$02,$02,$02,$22,$1C,$00 +byte = $1E,$22,$22,$22,$22,$22,$1E,$00,$3E,$02,$02,$1E,$02,$02,$3E,$00 +byte = $3E,$02,$02,$1E,$02,$02,$02,$00,$3C,$02,$02,$02,$32,$22,$3C,$00 +byte = $22,$22,$22,$3E,$22,$22,$22,$00,$1C,$08,$08,$08,$08,$08,$1C,$00 +byte = $20,$20,$20,$20,$20,$22,$1C,$00,$22,$12,$0A,$06,$0A,$12,$22,$00 +byte = $02,$02,$02,$02,$02,$02,$3E,$00,$22,$36,$2A,$2A,$22,$22,$22,$00 +byte = $22,$22,$26,$2A,$32,$22,$22,$00,$1C,$22,$22,$22,$22,$22,$1C,$00 +byte = $1E,$22,$22,$1E,$02,$02,$02,$00,$1C,$22,$22,$22,$2A,$12,$2C,$00 +byte = $1E,$22,$22,$1E,$0A,$12,$22,$00,$1C,$22,$02,$1C,$20,$22,$1C,$00 +byte = $3E,$08,$08,$08,$08,$08,$08,$00,$22,$22,$22,$22,$22,$22,$1C,$00 +byte = $22,$22,$22,$22,$22,$14,$08,$00,$22,$22,$22,$2A,$2A,$36,$22,$00 +byte = $22,$22,$14,$08,$14,$22,$22,$00,$22,$22,$14,$08,$08,$08,$08,$00 +byte = $3E,$20,$10,$08,$04,$02,$3E,$00,$3E,$06,$06,$06,$06,$06,$3E,$00 +byte = $00,$02,$04,$08,$10,$20,$00,$00,$3E,$30,$30,$30,$30,$30,$3E,$00 +byte = $00,$00,$08,$14,$22,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$7F +byte = $00,$00,$00,$00,$00,$00,$00,$00,$08,$08,$08,$08,$08,$00,$08,$00 +byte = $14,$14,$14,$00,$00,$00,$00,$00,$14,$14,$3E,$14,$3E,$14,$14,$00 +byte = $08,$3C,$0A,$1C,$28,$1E,$08,$00,$06,$26,$10,$08,$04,$32,$30,$00 +byte = $04,$0A,$0A,$04,$2A,$12,$2C,$00,$08,$08,$08,$00,$00,$00,$00,$00 +byte = $08,$04,$02,$02,$02,$04,$08,$00,$08,$10,$20,$20,$20,$10,$08,$00 +byte = $08,$2A,$1C,$08,$1C,$2A,$08,$00,$00,$08,$08,$3E,$08,$08,$00,$00 +byte = $00,$00,$00,$00,$08,$08,$04,$00,$00,$00,$00,$3E,$00,$00,$00,$00 +byte = $00,$00,$00,$00,$00,$00,$08,$00,$00,$20,$10,$08,$04,$02,$00,$00 +byte = $1C,$22,$32,$2A,$26,$22,$1C,$00,$08,$0C,$08,$08,$08,$08,$1C,$00 +byte = $1C,$22,$20,$18,$04,$02,$3E,$00,$3E,$20,$10,$18,$20,$22,$1C,$00 +byte = $10,$18,$14,$12,$3E,$10,$10,$00,$3E,$02,$1E,$20,$20,$22,$1C,$00 +byte = $38,$04,$02,$1E,$22,$22,$1C,$00,$3E,$20,$10,$08,$04,$04,$04,$00 +byte = $1C,$22,$22,$1C,$22,$22,$1C,$00,$1C,$22,$22,$3C,$20,$10,$0E,$00 +byte = $00,$00,$08,$00,$08,$00,$00,$00,$00,$00,$08,$00,$08,$08,$04,$00 +byte = $10,$08,$04,$02,$04,$08,$10,$00,$00,$00,$3E,$00,$3E,$00,$00,$00 +byte = $04,$08,$10,$20,$10,$08,$04,$00,$1C,$22,$10,$08,$08,$00,$08,$00 +byte = $1C,$22,$2A,$3A,$1A,$02,$3C,$00,$08,$14,$22,$22,$3E,$22,$22,$00 +byte = $1E,$22,$22,$1E,$22,$22,$1E,$00,$1C,$22,$02,$02,$02,$22,$1C,$00 +byte = $1E,$22,$22,$22,$22,$22,$1E,$00,$3E,$02,$02,$1E,$02,$02,$3E,$00 +byte = $3E,$02,$02,$1E,$02,$02,$02,$00,$3C,$02,$02,$02,$32,$22,$3C,$00 +byte = $22,$22,$22,$3E,$22,$22,$22,$00,$1C,$08,$08,$08,$08,$08,$1C,$00 +byte = $20,$20,$20,$20,$20,$22,$1C,$00,$22,$12,$0A,$06,$0A,$12,$22,$00 +byte = $02,$02,$02,$02,$02,$02,$3E,$00,$22,$36,$2A,$2A,$22,$22,$22,$00 +byte = $22,$22,$26,$2A,$32,$22,$22,$00,$1C,$22,$22,$22,$22,$22,$1C,$00 +byte = $1E,$22,$22,$1E,$02,$02,$02,$00,$1C,$22,$22,$22,$2A,$12,$2C,$00 +byte = $1E,$22,$22,$1E,$0A,$12,$22,$00,$1C,$22,$02,$1C,$20,$22,$1C,$00 +byte = $3E,$08,$08,$08,$08,$08,$08,$00,$22,$22,$22,$22,$22,$22,$1C,$00 +byte = $22,$22,$22,$22,$22,$14,$08,$00,$22,$22,$22,$2A,$2A,$36,$22,$00 +byte = $22,$22,$14,$08,$14,$22,$22,$00,$22,$22,$14,$08,$08,$08,$08,$00 +byte = $3E,$20,$10,$08,$04,$02,$3E,$00,$3E,$06,$06,$06,$06,$06,$3E,$00 +byte = $00,$02,$04,$08,$10,$20,$00,$00,$3E,$30,$30,$30,$30,$30,$3E,$00 +byte = $00,$00,$08,$14,$22,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$7F +byte = $00,$00,$00,$00,$00,$00,$00,$00,$08,$08,$08,$08,$08,$00,$08,$00 +byte = $14,$14,$14,$00,$00,$00,$00,$00,$14,$14,$3E,$14,$3E,$14,$14,$00 +byte = $08,$3C,$0A,$1C,$28,$1E,$08,$00,$06,$26,$10,$08,$04,$32,$30,$00 +byte = $04,$0A,$0A,$04,$2A,$12,$2C,$00,$08,$08,$08,$00,$00,$00,$00,$00 +byte = $08,$04,$02,$02,$02,$04,$08,$00,$08,$10,$20,$20,$20,$10,$08,$00 +byte = $08,$2A,$1C,$08,$1C,$2A,$08,$00,$00,$08,$08,$3E,$08,$08,$00,$00 +byte = $00,$00,$00,$00,$08,$08,$04,$00,$00,$00,$00,$3E,$00,$00,$00,$00 +byte = $00,$00,$00,$00,$00,$00,$08,$00,$00,$20,$10,$08,$04,$02,$00,$00 +byte = $1C,$22,$32,$2A,$26,$22,$1C,$00,$08,$0C,$08,$08,$08,$08,$1C,$00 +byte = $1C,$22,$20,$18,$04,$02,$3E,$00,$3E,$20,$10,$18,$20,$22,$1C,$00 +byte = $10,$18,$14,$12,$3E,$10,$10,$00,$3E,$02,$1E,$20,$20,$22,$1C,$00 +byte = $38,$04,$02,$1E,$22,$22,$1C,$00,$3E,$20,$10,$08,$04,$04,$04,$00 +byte = $1C,$22,$22,$1C,$22,$22,$1C,$00,$1C,$22,$22,$3C,$20,$10,$0E,$00 +byte = $00,$00,$08,$00,$08,$00,$00,$00,$00,$00,$08,$00,$08,$08,$04,$00 +byte = $10,$08,$04,$02,$04,$08,$10,$00,$00,$00,$3E,$00,$3E,$00,$00,$00 +byte = $04,$08,$10,$20,$10,$08,$04,$00,$1C,$22,$10,$08,$08,$00,$08,$00 +byte = $1C,$22,$2A,$3A,$1A,$02,$3C,$00,$08,$14,$22,$22,$3E,$22,$22,$00 +byte = $1E,$22,$22,$1E,$22,$22,$1E,$00,$1C,$22,$02,$02,$02,$22,$1C,$00 +byte = $1E,$22,$22,$22,$22,$22,$1E,$00,$3E,$02,$02,$1E,$02,$02,$3E,$00 +byte = $3E,$02,$02,$1E,$02,$02,$02,$00,$3C,$02,$02,$02,$32,$22,$3C,$00 +byte = $22,$22,$22,$3E,$22,$22,$22,$00,$1C,$08,$08,$08,$08,$08,$1C,$00 +byte = $20,$20,$20,$20,$20,$22,$1C,$00,$22,$12,$0A,$06,$0A,$12,$22,$00 +byte = $02,$02,$02,$02,$02,$02,$3E,$00,$22,$36,$2A,$2A,$22,$22,$22,$00 +byte = $22,$22,$26,$2A,$32,$22,$22,$00,$1C,$22,$22,$22,$22,$22,$1C,$00 +byte = $1E,$22,$22,$1E,$02,$02,$02,$00,$1C,$22,$22,$22,$2A,$12,$2C,$00 +byte = $1E,$22,$22,$1E,$0A,$12,$22,$00,$1C,$22,$02,$1C,$20,$22,$1C,$00 +byte = $3E,$08,$08,$08,$08,$08,$08,$00,$22,$22,$22,$22,$22,$22,$1C,$00 +byte = $22,$22,$22,$22,$22,$14,$08,$00,$22,$22,$22,$2A,$2A,$36,$22,$00 +byte = $22,$22,$14,$08,$14,$22,$22,$00,$22,$22,$14,$08,$08,$08,$08,$00 +byte = $3E,$20,$10,$08,$04,$02,$3E,$00,$3E,$06,$06,$06,$06,$06,$3E,$00 +byte = $00,$02,$04,$08,$10,$20,$00,$00,$3E,$30,$30,$30,$30,$30,$3E,$00 +byte = $00,$00,$08,$14,$22,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$7F +byte = $00,$00,$00,$00,$00,$00,$00,$00,$08,$08,$08,$08,$08,$00,$08,$00 +byte = $14,$14,$14,$00,$00,$00,$00,$00,$14,$14,$3E,$14,$3E,$14,$14,$00 +byte = $08,$3C,$0A,$1C,$28,$1E,$08,$00,$06,$26,$10,$08,$04,$32,$30,$00 +byte = $04,$0A,$0A,$04,$2A,$12,$2C,$00,$08,$08,$08,$00,$00,$00,$00,$00 +byte = $08,$04,$02,$02,$02,$04,$08,$00,$08,$10,$20,$20,$20,$10,$08,$00 +byte = $08,$2A,$1C,$08,$1C,$2A,$08,$00,$00,$08,$08,$3E,$08,$08,$00,$00 +byte = $00,$00,$00,$00,$08,$08,$04,$00,$00,$00,$00,$3E,$00,$00,$00,$00 +byte = $00,$00,$00,$00,$00,$00,$08,$00,$00,$20,$10,$08,$04,$02,$00,$00 +byte = $1C,$22,$32,$2A,$26,$22,$1C,$00,$08,$0C,$08,$08,$08,$08,$1C,$00 +byte = $1C,$22,$20,$18,$04,$02,$3E,$00,$3E,$20,$10,$18,$20,$22,$1C,$00 +byte = $10,$18,$14,$12,$3E,$10,$10,$00,$3E,$02,$1E,$20,$20,$22,$1C,$00 +byte = $38,$04,$02,$1E,$22,$22,$1C,$00,$3E,$20,$10,$08,$04,$04,$04,$00 +byte = $1C,$22,$22,$1C,$22,$22,$1C,$00,$1C,$22,$22,$3C,$20,$10,$0E,$00 +byte = $00,$00,$08,$00,$08,$00,$00,$00,$00,$00,$08,$00,$08,$08,$04,$00 +byte = $10,$08,$04,$02,$04,$08,$10,$00,$00,$00,$3E,$00,$3E,$00,$00,$00 +byte = $04,$08,$10,$20,$10,$08,$04,$00,$1C,$22,$10,$08,$08,$00,$08,$00 +byte = $1C,$22,$2A,$3A,$1A,$02,$3C,$00,$08,$14,$22,$22,$3E,$22,$22,$00 +byte = $1E,$22,$22,$1E,$22,$22,$1E,$00,$1C,$22,$02,$02,$02,$22,$1C,$00 +byte = $1E,$22,$22,$22,$22,$22,$1E,$00,$3E,$02,$02,$1E,$02,$02,$3E,$00 +byte = $3E,$02,$02,$1E,$02,$02,$02,$00,$3C,$02,$02,$02,$32,$22,$3C,$00 +byte = $22,$22,$22,$3E,$22,$22,$22,$00,$1C,$08,$08,$08,$08,$08,$1C,$00 +byte = $20,$20,$20,$20,$20,$22,$1C,$00,$22,$12,$0A,$06,$0A,$12,$22,$00 +byte = $02,$02,$02,$02,$02,$02,$3E,$00,$22,$36,$2A,$2A,$22,$22,$22,$00 +byte = $22,$22,$26,$2A,$32,$22,$22,$00,$1C,$22,$22,$22,$22,$22,$1C,$00 +byte = $1E,$22,$22,$1E,$02,$02,$02,$00,$1C,$22,$22,$22,$2A,$12,$2C,$00 +byte = $1E,$22,$22,$1E,$0A,$12,$22,$00,$1C,$22,$02,$1C,$20,$22,$1C,$00 +byte = $3E,$08,$08,$08,$08,$08,$08,$00,$22,$22,$22,$22,$22,$22,$1C,$00 +byte = $22,$22,$22,$22,$22,$14,$08,$00,$22,$22,$22,$2A,$2A,$36,$22,$00 +byte = $22,$22,$14,$08,$14,$22,$22,$00,$22,$22,$14,$08,$08,$08,$08,$00 +byte = $3E,$20,$10,$08,$04,$02,$3E,$00,$3E,$06,$06,$06,$06,$06,$3E,$00 +byte = $00,$02,$04,$08,$10,$20,$00,$00,$3E,$30,$30,$30,$30,$30,$3E,$00 +byte = $00,$00,$08,$14,$22,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$7F +byte = $04,$08,$10,$00,$00,$00,$00,$00,$00,$00,$1C,$20,$3C,$22,$3C,$00 +byte = $02,$02,$1E,$22,$22,$22,$1E,$00,$00,$00,$3C,$02,$02,$02,$3C,$00 +byte = $20,$20,$3C,$22,$22,$22,$3C,$00,$00,$00,$1C,$22,$3E,$02,$3C,$00 +byte = $18,$24,$04,$1E,$04,$04,$04,$00,$00,$00,$1C,$22,$22,$3C,$20,$1C +byte = $02,$02,$1E,$22,$22,$22,$22,$00,$08,$00,$0C,$08,$08,$08,$1C,$00 +byte = $10,$00,$18,$10,$10,$10,$12,$0C,$02,$02,$22,$12,$0E,$12,$22,$00 +byte = $0C,$08,$08,$08,$08,$08,$1C,$00,$00,$00,$36,$2A,$2A,$22,$22,$00 +byte = $00,$00,$1E,$22,$22,$22,$22,$00,$00,$00,$1C,$22,$22,$22,$1C,$00 +byte = $00,$00,$1E,$22,$22,$1E,$02,$02,$00,$00,$3C,$22,$22,$3C,$20,$20 +byte = $00,$00,$3A,$06,$02,$02,$02,$00,$00,$00,$3C,$02,$1C,$20,$1E,$00 +byte = $04,$04,$1E,$04,$04,$24,$18,$00,$00,$00,$22,$22,$22,$32,$2C,$00 +byte = $00,$00,$22,$22,$22,$14,$08,$00,$00,$00,$22,$22,$2A,$2A,$36,$00 +byte = $00,$00,$22,$14,$08,$14,$22,$00,$00,$00,$22,$22,$22,$3C,$20,$1C +byte = $00,$00,$3E,$10,$08,$04,$3E,$00,$38,$0C,$0C,$06,$0C,$0C,$38,$00 +byte = $08,$08,$08,$08,$08,$08,$08,$08,$0E,$18,$18,$30,$18,$18,$0E,$00 +byte = $00,$2C,$1A,$00,$00,$00,$00,$00,$00,$2A,$14,$2A,$14,$2A,$00,$00 +// +// Print string with HGR tile library +// +export def hgrPutStr(x, y, strptr)#0 + tileDrawStr(x, y, strptr + 1, ^strptr, @hgrFont + 1024) // Offset into regular char +end +done diff --git a/src/libsrc/apple/hgrlib.pla b/src/libsrc/apple/hgrlib.pla new file mode 100644 index 0000000..395fa78 --- /dev/null +++ b/src/libsrc/apple/hgrlib.pla @@ -0,0 +1,1281 @@ +include "inc/cmdsys.plh" +// +// Hardware addresses +// +const showgraphics = $C050 +const showtext = $C051 +const showfull = $C052 +const showmix = $C053 +const showpage1 = $C054 +const showpage2 = $C055 +const showlores = $C056 +const showhires = $C057 +const keyboard = $C000 +const keystrobe = $C010 +const hgr1 = $2000 +const hgr2 = $4000 +const page1 = 0 +const page2 = 1 +word hgrbuff[] = hgr1, hgr2 +//word hgrscan[] = $0000,$0400,$0800,$0C00,$1000,$1400,$1800,$1C00 +//word = $0080,$0480,$0880,$0C80,$1080,$1480,$1880,$1C80 +//word = $0100,$0500,$0900,$0D00,$1100,$1500,$1900,$1D00 +//word = $0180,$0580,$0980,$0D80,$1180,$1580,$1980,$1D80 +//word = $0200,$0600,$0A00,$0E00,$1200,$1600,$1A00,$1E00 +//word = $0280,$0680,$0A80,$0E80,$1280,$1680,$1A80,$1E80 +//word = $0300,$0700,$0B00,$0F00,$1300,$1700,$1B00,$1F00 +//word = $0380,$0780,$0B80,$0F80,$1380,$1780,$1B80,$1F80 +//word = $0028,$0428,$0828,$0C28,$1028,$1428,$1828,$1C28 +//word = $00A8,$04A8,$08A8,$0CA8,$10A8,$14A8,$18A8,$1CA8 +//word = $0128,$0528,$0928,$0D28,$1128,$1528,$1928,$1D28 +//word = $01A8,$05A8,$09A8,$0DA8,$11A8,$15A8,$19A8,$1DA8 +//word = $0228,$0628,$0A28,$0E28,$1228,$1628,$1A28,$1E28 +//word = $02A8,$06A8,$0AA8,$0EA8,$12A8,$16A8,$1AA8,$1EA8 +//word = $0328,$0728,$0B28,$0F28,$1328,$1728,$1B28,$1F28 +//word = $03A8,$07A8,$0BA8,$0FA8,$13A8,$17A8,$1BA8,$1FA8 +//word = $0050,$0450,$0850,$0C50,$1050,$1450,$1850,$1C50 +//word = $00D0,$04D0,$08D0,$0CD0,$10D0,$14D0,$18D0,$1CD0 +//word = $0150,$0550,$0950,$0D50,$1150,$1550,$1950,$1D50 +//word = $01D0,$05D0,$09D0,$0DD0,$11D0,$15D0,$19D0,$1DD0 +//word = $0250,$0650,$0A50,$0E50,$1250,$1650,$1A50,$1E50 +//word = $02D0,$06D0,$0AD0,$0ED0,$12D0,$16D0,$1AD0,$1ED0 +//word = $0350,$0750,$0B50,$0F50,$1350,$1750,$1B50,$1F50 +//word = $03D0,$07D0,$0BD0,$0FD0,$13D0,$17D0,$1BD0,$1FD0 +//word hmask = $8081,$8082,$8084,$8088,$8090,$80A0,$80C0 +//word = $8180,$8280,$8480,$8880,$9080,$A080,$C080 +byte hgrscanl[]= $00,$00,$00,$00,$00,$00,$00,$00 +byte = $80,$80,$80,$80,$80,$80,$80,$80 +byte = $00,$00,$00,$00,$00,$00,$00,$00 +byte = $80,$80,$80,$80,$80,$80,$80,$80 +byte = $00,$00,$00,$00,$00,$00,$00,$00 +byte = $80,$80,$80,$80,$80,$80,$80,$80 +byte = $00,$00,$00,$00,$00,$00,$00,$00 +byte = $80,$80,$80,$80,$80,$80,$80,$80 +byte = $28,$28,$28,$28,$28,$28,$28,$28 +byte = $A8,$A8,$A8,$A8,$A8,$A8,$A8,$A8 +byte = $28,$28,$28,$28,$28,$28,$28,$28 +byte = $A8,$A8,$A8,$A8,$A8,$A8,$A8,$A8 +byte = $28,$28,$28,$28,$28,$28,$28,$28 +byte = $A8,$A8,$A8,$A8,$A8,$A8,$A8,$A8 +byte = $28,$28,$28,$28,$28,$28,$28,$28 +byte = $A8,$A8,$A8,$A8,$A8,$A8,$A8,$A8 +byte = $50,$50,$50,$50,$50,$50,$50,$50 +byte = $D0,$D0,$D0,$D0,$D0,$D0,$D0,$D0 +byte = $50,$50,$50,$50,$50,$50,$50,$50 +byte = $D0,$D0,$D0,$D0,$D0,$D0,$D0,$D0 +byte = $50,$50,$50,$50,$50,$50,$50,$50 +byte = $D0,$D0,$D0,$D0,$D0,$D0,$D0,$D0 +byte = $50,$50,$50,$50,$50,$50,$50,$50 +byte = $D0,$D0,$D0,$D0,$D0,$D0,$D0,$D0 +byte hgrscanh[]= $00,$04,$08,$0C,$10,$14,$18,$1C +byte = $00,$04,$08,$0C,$10,$14,$18,$1C +byte = $01,$05,$09,$0D,$11,$15,$19,$1D +byte = $01,$05,$09,$0D,$11,$15,$19,$1D +byte = $02,$06,$0A,$0E,$12,$16,$1A,$1E +byte = $02,$06,$0A,$0E,$12,$16,$1A,$1E +byte = $03,$07,$0B,$0F,$13,$17,$1B,$1F +byte = $03,$07,$0B,$0F,$13,$17,$1B,$1F +byte = $00,$04,$08,$0C,$10,$14,$18,$1C +byte = $00,$04,$08,$0C,$10,$14,$18,$1C +byte = $01,$05,$09,$0D,$11,$15,$19,$1D +byte = $01,$05,$09,$0D,$11,$15,$19,$1D +byte = $02,$06,$0A,$0E,$12,$16,$1A,$1E +byte = $02,$06,$0A,$0E,$12,$16,$1A,$1E +byte = $03,$07,$0B,$0F,$13,$17,$1B,$1F +byte = $03,$07,$0B,$0F,$13,$17,$1B,$1F +byte = $00,$04,$08,$0C,$10,$14,$18,$1C +byte = $00,$04,$08,$0C,$10,$14,$18,$1C +byte = $01,$05,$09,$0D,$11,$15,$19,$1D +byte = $01,$05,$09,$0D,$11,$15,$19,$1D +byte = $02,$06,$0A,$0E,$12,$16,$1A,$1E +byte = $02,$06,$0A,$0E,$12,$16,$1A,$1E +byte = $03,$07,$0B,$0F,$13,$17,$1B,$1F +byte = $03,$07,$0B,$0F,$13,$17,$1B,$1F +byte hbmask = $81,$82,$84,$88,$90,$A0,$C0 +byte hlmask = $FF,$FE,$FC,$F8,$F0,$E0,$C0 +byte hrmask = $81,$83,$87,$8F,$9F,$BF,$FF +word hcolor[] = $0000,$552A,$2A55,$7F7F,$8080,$D5AA,$AAD5,$FFFF +word curhclr +byte drawpage = 1 +word drawbuff = hgr2 + +export asm divmod7(x)#2 +!SOURCE "vmsrc/plvmzp.inc" + LDA ESTKL+0,X ; X COORDL + LDY ESTKH+0,X ; X COORDH + BPL + + TYA ; DEAL WITH NEG X COORD + EOR #$FF + TAY + LDA ESTKL+0,X + EOR #$FF ++ CPY #$01 + BEQ ++ ; MUST BE >= 140 + BCC + + LDY #40 ; > 512 SO CLIP AT MAX + LDA #00 + BEQ +++ ++ CMP #140 + BCC + +++ SEC + SBC #140 + LDY #20 ++ CMP #70 + BCC + + SBC #70 + STA ESTKL+0,X + TYA + ADC #9 + TAY + LDA ESTKL+0,X ++ CMP #35 + BCC + + SBC #35 + STA ESTKL+0,X + TYA + ADC #4 + TAY + LDA ESTKL+0,X ++ +- CMP #7 + BCC +++ + SBC #7 + INY + BNE - ++++ DEX + ASL ESTKH+1,X ; CHECK SIGN OF XCOORD + BCS + + STA ESTKL+0,X ; REMAINDERL + STY ESTKL+1,X ; QUOTIENTL + LDY #$00 + STY ESTKH+0,X + STY ESTKH+1,X + RTS ++ EOR #$07 + SBC #$01 + STA ESTKL+0,X ; REMAINDERL + TYA + EOR #$FF + STA ESTKL+1,X ; QUOTIENTL + LDY #$00 + STY ESTKH+0,X + DEY + STY ESTKH+1,X + RTS +end +asm clipsrc(ofst, y, w, h, srcptr)#0 + LDA ESTKL+0,X ; SRC PTR + STA SRCL + LDA ESTKH+0,X + STA SRCH + LDA ESTKL+2,X ; WIDTH (SRC PITCH) + STA TMPH ; WIDTH (DRAW WIDTH) +; CLPTOP + LDY ESTKH+3,X ; Y COORDH + BPL CLPBOTM + INY +; STY ESTKH+3,X ; Y COORDH + BNE CLPPED + LDY ESTKL+3,X ; Y COORDL +- LDA SRCL + CLC + ADC ESTKL+2,X ; PITCH + STA SRCL + BCC + + INC SRCH ++ DEC ESTKL+1,X ; HEIGHT + BEQ CLPPED + INY ; Y COORDL + BNE - + STY ESTKL+3,X ; Y COORDL + BEQ CLPLEFT ; BETTER BE ZERO +CLPBOTM BNE CLPPED + LDA ESTKL+3,X ; YCOORDL + CMP #192 + BCS CLPPED +; CLC + ADC ESTKL+1,X ; HEIGHT + SBC #191 + BCC CLPLEFT + STA TMPL + LDA ESTKL+1,X ; HEIGHT + SBC TMPL + STA ESTKL+1,X ; HEIGHT + BEQ CLPPED +CLPLEFT LDY ESTKH+4,X ; HORIZ OFFSETH + BPL CLPRGHT + INY +; STY ESTKH+4,X + BNE CLPPED + LDY ESTKL+4,X ; HORIZ OFFSETL +- INC SRCL + BNE + + INC SRCH ++ DEC TMPH ; WIDTH + BEQ CLPPED + INY ; HORIZ OFFSETL + BNE - + STY ESTKL+4,X ; HORIZ OFFSETL + BEQ CLPDONE ; BETTER BE ZERO +CLPRGHT BNE CLPPED + LDA ESTKL+4,X ; HORIZ OFFSETL + CMP #40 + BCS CLPPED +; CLC + ADC TMPH ; WIDTH + SBC #39 + BCC CLPDONE + STA TMPL + LDA TMPH ; WIDTH + SBC TMPL + STA TMPH ; WIDTH +CLPDONE LDA TMPH + STA ESTKH+2,X ; WIDTH (DRAW WIDTH) +; LDA SRCL +; STA ESTKL+0,X ; SRC PTR +; LDA SRCH +; STA ESTKH+0,X + RTS +CLPPED INX + INX + INX + INX + INX + PLA + PLA + RTS +end +//export def hgrColor(c)#0 +// curhclr = hcolor[c & $07] +//end +export asm hgrColor(c)#0 + LDA ESTKL+0,X ; COLOR + AND #$07 + ASL + TAY + LDA $1000,Y ; HCOLORL + STA $2000 ; CURHCLRL + LDA $1001,Y ; HCOLORH + STA $2001 ; CRHCLRH + INX + RTS +end +//export def hgrCopyDst(ofst, y, w, h, dstptr)#0 +// word j, srcptr +// +// ofst = ofst + drawbuff +// for j = y to y + h - 1 +// srcptr = hgrscan[j] + ofst +// memcpy(dstptr, srcptr, w) +// dstptr = dstptr + w +// next +//end +export asm hgrCopyDst(ofst, y, w, h, dstptr)#0 + JSR $C000 ; CLIPSRC +; LDA ESTKL+0,X ; DST PTR + LDA SRCL + STA DSTL +; LDA ESTKH+0,X + LDA SRCH + STA DSTH +-- LDY ESTKL+3,X ; Y COORD + LDA ESTKL+4,X ; HORIZ OFFSET + CLC +end +asm _hgrCopyDst + ADC $8000,Y ; HGRSCANL + STA SRCL + LDA $1000 ; DRAWBUFFH + ADC $9000,Y ; HGRSCANH + STA SRCH + LDY ESTKH+2,X ; WIDTH + DEY +- LDA (SRC),Y + STA (DST),Y + DEY + BPL - + LDA DSTL + CLC + ADC ESTKL+2,X ; PITCH + STA DSTL + BCC + + INC DSTH ++ INC ESTKL+3,X ; Y COORD + DEC ESTKL+1,X ; HEIGHT + BNE -- + INX + INX + INX + INX + INX + RTS +end +//export def hgrCopySrc(ofst, y, w, h, srcptr)#0 +// word j, dstptr +// +// ofst = ofst + drawbuff +// for j = y to y + h - 1 +// dstptr = hgrscan[j] + ofst +// memcpy(dstptr, srcptr, w) +// srcptr = srcptr + w +// next +//end +export asm hgrCopySrc(ofst, y, w, h, srcptr)#0 + JSR $C000 ; CLIPSRC +; LDA ESTKL+0,X ; SRC PTR +; STA SRCL +; LDA ESTKH+0,X +; STA SRCH +-- LDY ESTKL+3,X ; Y COORD + LDA ESTKL+4,X ; HORIZ OFFSET + CLC +end +asm _hgrCopySrc + ADC $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ADC $9000,Y ; HGRSCANH + STA DSTH + LDY ESTKH+2,X ; WIDTH + DEY +- LDA (SRC),Y + STA (DST),Y + DEY + BPL - + LDA SRCL + CLC + ADC ESTKL+2,X ; PITCH + STA SRCL + BCC + + INC SRCH ++ INC ESTKL+3,X ; Y COORD + DEC ESTKL+1,X ; HEIGHT + BNE -- + INX + INX + INX + INX + INX + RTS +end +//export def hgrAndSrc(ofst, y, w, h, srcptr)#0 +// word j, dstptr +// byte i +// +// ofst = ofst + drawbuff +// for j = y to y + h - 1 +// dstptr = hgrscan[j] + ofst +// for i = 0 to w - 1 +// dstptr->[i] = dstptr->[i] & srcptr->[i] +// next +// srcptr = srcptr + w +// next +//end +export asm hgrAndSrc(ofst, y, w, h, srcptr)#0 + JSR $C000 ; CLIPSRC +; LDA ESTKL+0,X ; SRC PTR +; STA SRCL +; LDA ESTKH+0,X +; STA SRCH +-- LDY ESTKL+3,X ; Y COORD + LDA ESTKL+4,X ; HORIZ OFFSET + CLC +end +asm _hgrAndSrc + ADC $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ADC $9000,Y ; HGRSCANH + STA DSTH + LDY ESTKH+2,X ; WIDTH + DEY +- LDA (SRC),Y + AND (DST),Y + STA (DST),Y + DEY + BPL - + LDA SRCL + CLC + ADC ESTKL+2,X ; PITCH + STA SRCL + BCC + + INC SRCH ++ INC ESTKL+3,X ; Y COORD + DEC ESTKL+1,X ; HEIGHT + BNE -- + INX + INX + INX + INX + INX + RTS +end +//export def hgrXorSrc(ofst, y, w, h, srcptr)#0 +// word j, dstptr +// byte i +// +// ofst = ofst + drawbuff +// for j = y to y + h - 1 +// dstptr = hgrscan[j] + ofst +// for i = 0 to w - 1 +// dstptr->[i] = dstptr->[i] ^ srcptr->[i] +// next +// srcptr = srcptr + w +// next +//end +export asm hgrXorSrc(ofst, y, w, h, srcptr)#0 + JSR $C000 ; CLIPSRC +; LDA ESTKL+0,X ; SRC PTR +; STA SRCL +; LDA ESTKH+0,X +; STA SRCH +-- LDY ESTKL+3,X ; Y COORD + LDA ESTKL+4,X ; HORIZ OFFSET + CLC +end +asm _hgrXorSrc + ADC $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ADC $9000,Y ; HGRSCANH + STA DSTH + LDY ESTKH+2,X ; WIDTH + DEY +- LDA (SRC),Y + EOR (DST),Y + STA (DST),Y + DEY + BPL - + LDA SRCL + CLC + ADC ESTKL+2,X ; PITCH + STA SRCL + BCC + + INC SRCH ++ INC ESTKL+3,X ; Y COORD + DEC ESTKL+1,X ; HEIGHT + BNE -- + INX + INX + INX + INX + INX + RTS +end +//export def hgrOrSrc(ofst, y, w, h, srcptr)#0 +// word j, dstptr +// byte i +// +// ofst = ofst + drawbuff +// for j = y to y + h - 1 +// dstptr = hgrscan[j] + ofst +// for i = 0 to w - 1 +// dstptr->[i] = dstptr->[i] ^ srcptr->[i] +// next +// srcptr = srcptr + w +// next +//end +export asm hgrOrSrc(ofst, y, w, h, srcptr)#0 + JSR $C000 ; CLIPSRC +; LDA ESTKL+0,X ; SRC PTR +; STA SRCL +; LDA ESTKH+0,X +; STA SRCH +-- LDY ESTKL+3,X ; Y COORD + LDA ESTKL+4,X ; HORIZ OFFSET + CLC +end +asm _hgrOrSrc + ADC $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ADC $9000,Y ; HGRSCANH + STA DSTH + LDY ESTKH+2,X ; WIDTH + DEY +- LDA (SRC),Y + ORA (DST),Y + STA (DST),Y + DEY + BPL - + LDA SRCL + CLC + ADC ESTKL+2,X ; PITCH + STA SRCL + BCC + + INC SRCH ++ INC ESTKL+3,X ; Y COORD + DEC ESTKL+1,X ; HEIGHT + BNE -- + INX + INX + INX + INX + INX + RTS +end +//export def hgrPlot(x, y)#0 +// word pixptr +// byte ofst, pixofst, pmask +// +// ofst, pixofst = divmod7(x) +// pixptr = hgrscan[y] + drawbuff + ofst +// pmask = hbmask[pixofst] +// ^pixptr = (^pixptr & ~pmask) | (curhclr.[ofst & 1] & pmask) +//end +export asm hgrPlot(x, y)#0 + LDY ESTKL+0,X ; Y COORD + CPY #192 + BCS + +end +asm _hgrPlotA + LDA $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ORA $9000,Y ; HGRSCANH + STA DSTH + INX +end +asm _hgrPlotB + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; PIXEL OFFSET +end +asm _hgrPlotC + LDA $1000,Y ; HBMASK + STA TMPL + LDA ESTKL+1,X ; HORIZ OFFSET + CMP #40 + BCS + + AND #$01 + TAY +end +asm _hgrPlotD + LDA $2000,Y ; CURHCLR + LDY ESTKL+1,X ; HORIZ OFFSET + EOR (DST),Y + AND TMPL + EOR (DST),Y + STA (DST),Y ++ INX + INX + RTS +end +//export def hgrXorPlot(x, y)#0 +// word pixptr +// byte ofst, pixofst, pmask +// +// ofst, pixofst = divmod7(x) +// pixptr = hgrscan[y] + drawbuff + ofst +// pmask = hbmask[pixofst] +// ^pixptr = ^pixptr ^ (curhclr.[ofst & 1] & pmask) +//end +export asm hgrXorPlot(x, y)#0 + LDY ESTKL+0,X ; Y COORD + CPY #192 + BCS + +end +asm _hgrXorPlotA + LDA $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ORA $9000,Y ; HGRSCANH + STA DSTH + INX +end +asm _hgrXorPlotB + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; PIXEL OFFSET +end +asm _hgrXorPlotC + LDA $1000,Y ; HBMASK + STA TMPL + LDA ESTKL+1,X ; HORIZ OFFSET + CMP #40 + BCS + + AND #$01 + TAY +end +asm _hgrXorPlotD + LDA $2000,Y ; CURHCLR + LDY ESTKL+1,X ; HORIZ OFFSET + AND TMPL + EOR (DST),Y + STA (DST),Y ++ INX + INX + RTS +end +//export def hgrOrPlot(x, y)#0 +// word pixptr +// byte ofst, pixofst, pmask +// +// ofst, pixofst = divmod7(x) +// pixptr = hgrscan[y] + drawbuff + ofst +// pmask = hbmask[pixofst] +// ^pixptr = ^pixptr | (curhclr.[ofst & 1] & pmask) +//end +export asm hgrOrPlot(x, y)#0 + LDY ESTKL+0,X ; Y COORD + CPY #192 + BCS + +end +asm _hgrOrPlotA + LDA $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ORA $9000,Y ; HGRSCANH + STA DSTH + INX +end +asm _hgrOrPlotB + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; PIXEL OFFSET +end +asm _hgrOrPlotC + LDA $1000,Y ; HBMASK + STA TMPL + LDA ESTKL+1,X ; HORIZ OFFSET + CMP #40 + BCS + + AND #$01 + TAY +end +asm _hgrOrPlotD + LDA $2000,Y ; CURHCLR + LDY ESTKL+1,X ; HORIZ OFFSET + AND TMPL + ORA (DST),Y + STA (DST),Y ++ INX + INX + RTS +end +//export def hgrHLin(x1, x2, y)#0 +// word pixptr, x +// byte lofst, lpixofst, lpmask +// byte rofst, rpixofst, rpmask +// +// if x1 == x2 +// hgrPlot(x1, y) +// else +// lofst, lpixofst = divmod7(x1) +// pixptr = hgrscan[y] + drawbuff + lofst +// rofst, rpixofst = divmod7(x2) +// lpmask = hlmask[lpixofst] +// rpmask = hrmask[rpixofst] +// if lofst == rofst +// lpmask = lpmask & rpmask +// ^pixptr = (^pixptr & ~lpmask) | (curhclr.[pixptr.0 & 1] & lpmask) +// else +// ^pixptr = (^pixptr & ~lpmask) | (curhclr.[pixptr.0 & 1] & lpmask) +// pixptr++ +// for x = lofst + 1 to rofst - 1 +// ^pixptr = curhclr.[pixptr.0 & 1] +// pixptr++ +// next +// ^pixptr = (^pixptr & ~rpmask) | (curhclr.[pixptr.0 & 1] & rpmask) +// fin +// fin +//end +export asm hgrHLin(x1, x2, y)#0 + LDA ESTKL+1 + CMP ESTKL+2 + BNE + + LDA ESTKH+1 + CMP ESTKH+2 + BNE + +end +asm _hgrHLinA + JSR $F000 + INX + RTS ++ LDY ESTKL+0,X ; Y COORD +end +asm _hgrHLinB + LDA $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ORA $9000,Y ; HGRSCANH + STA DSTH + LDA ESTKL+1,X + STA ESTKL+0,X + LDA ESTKH+1,X + STA ESTKH+0,X +end +asm _hgrHLinC + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; RIGHT PIXEL OFFSET +end +asm _hgrHLinD + LDA $1000,Y ; HRMASK + STA TMPH + LDY ESTKL+1,X ; RIGHT HORIZ OFFSET + STY IPY ; STEAL THIS ZP FOR A MOMENT + INX + INX + INX +end +asm _hgrHLinE + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; LEFT PIXEL OFFSET +end +asm _hgrHLinF + LDA $1000,Y ; HLMASK + STA TMPL + LDY ESTKL+1,X ; LEFT HORIZ OFFSET + TYA + LSR + BCS + +end +asm _hgrHLinG + LDA $2001 ; CURHCLRH + STA SRCH + LDA $2000 ; CURHCLRL + STA SRCL + BCC ++ ++ LDA $2000 ; CURHCLRL + STA SRCH + LDA $2001 ; CURHCLRH + STA SRCL +++ CPY IPY ; RIGHT HORIZ OFFSET + BNE + + EOR (DST),Y + AND TMPL + AND TMPH + EOR (DST),Y + STA (DST),Y + INX + INX + RTS ++ EOR (DST),Y + AND TMPL + EOR (DST),Y +- STA (DST),Y + LDA SRCH + INY + CPY IPY ; RIGHT HORIZ OFFSET + BCS + + STA (DST),Y + LDA SRCL + INY + CPY IPY ; RIGHT HORIZ OFFSET + BCC - ++ EOR (DST),Y + AND TMPH + EOR (DST),Y + STA (DST),Y + INX + INX + RTS +end +//export def hgrXorHLin(x1, x2, y)#0 +// word pixptr, x +// byte lofst, lpixofst, lpmask +// byte rofst, rpixofst, rpmask +// +// if x1 == x2 +// hgrPlot(x1, y) +// else +// lofst, lpixofst = divmod7(x1) +// pixptr = hgrscan[y] + drawbuff + lofst +// rofst, rpixofst = divmod7(x2) +// lpmask = hlmask[lpixofst] +// rpmask = hrmask[rpixofst] +// if lofst == rofst +// lpmask = lpmask & rpmask +// ^pixptr = ^pixptr ^ (curhclr.[pixptr.0 & 1] & lpmask) +// else +// ^pixptr = ^pixptr ^ (curhclr.[pixptr.0 & 1] & lpmask) +// pixptr++ +// for x = lofst + 1 to rofst - 1 +// ^pixptr = ^pixptr ^ curhclr.[pixptr.0 & 1] +// pixptr++ +// next +// ^pixptr = ^pixptr ^ (curhclr.[pixptr.0 & 1] & rpmask) +// fin +// fin +//end +export asm hgrXorHLin(x1, x2, y)#0 + LDA ESTKL+1 + CMP ESTKL+2 + BNE + + LDA ESTKH+1 + CMP ESTKH+2 + BNE + +end +asm _hgrXHLinA + JSR $F000 + INX + RTS ++ LDY ESTKL+0,X ; Y COORD +end +asm _hgrXHLinB + LDA $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ORA $9000,Y ; HGRSCANH + STA DSTH + LDA ESTKL+1,X + STA ESTKL+0,X + LDA ESTKH+1,X + STA ESTKH+0,X +end +asm _hgrXHLinC + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; RIGHT PIXEL OFFSET +end +asm _hgrXHLinD + LDA $1000,Y ; HRMASK + STA TMPH + LDY ESTKL+1,X ; RIGHT HORIZ OFFSET + STY IPY ; STEAL THIS ZP FOR A MOMENT + INX + INX + INX +end +asm _hgrXHLinE + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; LEFT PIXEL OFFSET +end +asm _hgrXHLinF + LDA $1000,Y ; HLMASK + STA TMPL + LDY ESTKL+1,X ; LEFT HORIZ OFFSET + TYA + LSR + BCS + +end +asm _hgrXHLinG + LDA $2001 ; CURHCLRH + STA SRCH + LDA $2000 ; CURHCLRH + STA SRCL + BCC ++ ++ LDA $2000 ; CURHCLRL + STA SRCH + LDA $2001 ; CURHCLRH + STA SRCL +++ CPY IPY ; RIGHT HORIZ OFFSET + BNE + + AND TMPL + AND TMPH + EOR (DST),Y + STA (DST),Y + INX + INX + RTS ++ AND TMPL +- EOR (DST),Y + STA (DST),Y + LDA SRCH + INY + CPY IPY ; RIGHT HORIZ OFFSET + BCS + + EOR (DST),Y + STA (DST),Y + LDA SRCL + INY + CPY IPY ; RIGHT HORIZ OFFSET + BCC - ++ AND TMPH + EOR (DST),Y + STA (DST),Y + INX + INX + RTS +end +//export def hgrVlin(y1, y2, x)#0 +// word pixptr, y, ofst +// byte pixofst, pmask, cmask +// +// if y1 == y2 +// hgrPlot(x, y1) +// else +// ofst, pixofst = divmod7(x) +// ofst = ofst + drawbuff +// pmask = hbmask[pixofst] +// cmask = curhclr.[ofst & 1] & pmask +// pmask = ~pmask +// for y = y1 to y2 +// pixptr = hgrscan[y] + ofst +// ^pixptr = (^pixptr & pmask) | cmask +// next +// fin +//end +export asm hgrVlin(y1, y2, x)#0 + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; PIXEL OFFSET +end +asm _hgrVLinA + LDA $1000,Y ; HBMASK + STA TMPL + EOR #$FF + STA TMPH + LDA ESTKL+1,X ; HORIZ OFFSET + AND #$01 + TAY +end +asm _hgrVLinB + LDA $2000,Y ; CURHCLR + AND TMPL + STA TMPL + LDY ESTKL+3,X ; Y1 COORD +end +asm _hgrVLinC +- LDA $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ORA $9000,Y ; HGRSCANH + STA DSTH + LDY ESTKL+1,X ; HORIZ OFFSET + LDA (DST),Y + AND TMPH + ORA TMPL + STA (DST),Y + LDY ESTKL+3,X ; Y1 COORD + TYA + INY + STY ESTKL+3,X ; Y1 COORD + CMP ESTKL+2,X ; Y2 COORD + BNE - + INX + INX + INX + INX + RTS +end +//export def hgrXVlin(y1, y2, x)#0 +// word pixptr, y, ofst +// byte pixofst, pmask, cmask +// +// if y1 == y2 +// hgrXorPlot(x, y1) +// else +// ofst, pixofst = divmod7(x) +// ofst = ofst + drawbuff +// pmask = hbmask[pixofst] +// cmask = curhclr.[ofst & 1] & pmask +// pmask = ~pmask +// for y = y1 to y2 +// pixptr = hgrscan[y] + ofst +// ^pixptr = ^pixptr ^ cmask +// next +// fin +//end +export asm hgrXorVlin(y1, y2, x)#0 + JSR 1000 ; DIVMOD7 + LDY ESTKL+0,X ; PIXEL OFFSET +end +asm _hgrXVLinA + LDA $1000,Y ; HBMASK + STA TMPL + EOR #$FF + STA TMPH + LDA ESTKL+1,X ; HORIZ OFFSET + AND #$01 + TAY +end +asm _hgrXVLinB + LDA $2000,Y ; CURHCLR + AND TMPL + STA TMPL + LDY ESTKL+3,X ; Y1 COORD +end +asm _hgrXVLinC +- LDA $8000,Y ; HGRSCANL + STA DSTL + LDA $1000 ; DRAWBUFFH + ORA $9000,Y ; HGRSCANH + STA DSTH + LDY ESTKL+1,X ; HORIZ OFFSET + LDA TMPL + EOR (DST),Y + STA (DST),Y + LDY ESTKL+3,X ; Y1 COORD + TYA + INY + STY ESTKL+3,X ; Y1 COORD + CMP ESTKL+2,X ; Y2 COORD + BNE - + INX + INX + INX + INX + RTS +end +// +// Masked BLT scanline of pixmap +// +asm scanBLT(x, y, w, srcptr)#0 + LDA ESTKL+0,X ; SRC PTR + STA SRCL + LDA ESTKH+0,X + STA SRCH + LDA #$00 +- PHA + LSR + TAY + LDA (SRC),Y + LSR + LSR + LSR + LSR + PHA + DEX + STA ESTKL+0,X +end +asm _scanBLTA + JSR $C000 ; HCOLOR + DEX + DEX + LDA ESTKL+5,X ; X COORDL + STA ESTKL+1,X + LDA ESTKH+5,X ; X COORDH + STA ESTKH+1,X + LDA ESTKL+4,X ; Y COORDL + STA ESTKL+0,X + LDA ESTKH+4,X ; Y COORDH + STA ESTKH+0,X + PLA + AND #$08 + BEQ + +end +asm _scanBLTB + JSR $D000 ; HPLOT + BEQ ++ + BNE ++ ++ JSR $E000 ; HPLOTOR +++ INC ESTKL+3,X ; X COORDL + BNE + + INC ESTKH+3,X ; X COORDH ++ PLA + CLC + ADC #$01 + CMP ESTKL+1,X ; WIDTH + BEQ BLTDONE + PHA + LSR + TAY + LDA (SRC),Y + PHA + DEX + STA ESTKL+0,X +end +asm _scanBLTC + JSR $C000 ; HCOLOR + DEX + DEX + LDA ESTKL+5,X ; X COORDL + STA ESTKL+1,X + LDA ESTKH+5,X ; X COORDH + STA ESTKH+1,X + LDA ESTKL+4,X ; Y COORDL + STA ESTKL+0,X + LDA ESTKH+4,X ; Y COORDH + STA ESTKH+0,X + PLA + AND #$08 + BEQ + +end +asm _scanBLTD + JSR $D000 ; HPLOT + BEQ ++ + BNE ++ ++ JSR $E000 ; HPLOTOR +++ INC ESTKL+3,X ; X COORDL + BNE + + INC ESTKH+3,X ; X COORDH ++ PLA + CLC + ADC #$01 + CMP ESTKL+1,X ; WIDTH + BNE - +BLTDONE INX + INX + INX + INX + RTS +end +export def hgrRect(x1, y1, x2, y2)#0 + word y + + if x1 == x2 + hgrVLin(y1, y2, x1) + else + for y = y1 to y2 + hgrHLin(x1, x2, y) + next + fin +end +export def hgrXorRect(x1, y1, x2, y2)#0 + word y + + if x1 == x2 + hgrXorVLin(y1, y2, x1) + else + for y = y1 to y2 + hgrXorHLin(x1, x2, y) + next + fin +end +export def hgrBLT(x, y, w, h, srcptr)#0 + word i, j + word saveclr + byte c + + saveclr = curhclr + for j = y to y + h - 1 + scanBLT(x, j, w, srcptr) +// for i = 0 to w - 1 +// c = srcptr->[i >> 1] +// if i & 1 +// hgrColor(c) +// if c & $08 +// hgrOrPlot(x + i, j) +// else +// hgrPlot(x + i, j) +// fin +// else +// hgrColor(c >> 4) +// if c & $80 +// hgrXorPlot(x + i, j) +// else +// hgrPlot(x + i, j) +// fin +// fin +// next + srcptr = srcptr + (w + 1) / 2 + next + curhclr = saveclr +end +export def hgrMode(mode)#1 + if mode + // + // Set HGR mode + // + memset(hgr1, 0, $2000) // Clear HGR page 1 + ^showpage1 + ^showfull + ^showhires + ^showgraphics + drawpage = 1 + drawbuff = hgrbuff[1] + return 1 + fin + // + // Show text mode + // + ^showpage1 + ^showtext + return 0 +end +export def hgrClear#0 + memset(drawbuff, curhclr, drawbuff) // Clear current HGR page +end +// +// Set display page, return other page +// +export def hgrShow(page)#1 + page = page & 1 + ^(showpage1 + page) + return page ^ 1 +end +export def hgrSwap#1 + ^(showpage1 + drawpage) + drawpage = drawpage ^ 1 + drawbuff = hgrbuff[drawpage] + return drawpage +end +export def hgrDrawBuf(page)#1 + drawpage = page & 1 + drawbuff = hgrbuff[drawpage] + return drawpage +end +// +// Assembly fixups +// +hgrCopyDst:1 = @clipsrc +_hgrCopyDst:1 = @hgrscanl +_hgrCopyDst:6 = @drawbuff.1 +_hgrCopyDst:9 = @hgrscanh +hgrCopySrc:1 = @clipsrc +_hgrCopySrc:1 = @hgrscanl +_hgrCopySrc:6 = @drawbuff.1 +_hgrCopySrc:9 = @hgrscanh +hgrAndSrc:1 = @clipsrc +_hgrAndSrc:1 = @hgrscanl +_hgrAndSrc:6 = @drawbuff.1 +_hgrAndSrc:9 = @hgrscanh +hgrXorSrc:1 = @clipsrc +_hgrXorSrc:1 = @hgrscanl +_hgrXorSrc:6 = @drawbuff.1 +_hgrXorSrc:9 = @hgrscanh +hgrOrSrc:1 = @clipsrc +_hgrOrSrc:1 = @hgrscanl +_hgrOrSrc:6 = @drawbuff.1 +_hgrOrSrc:9 = @hgrscanh +_hgrPlotA:1 = @hgrscanl +_hgrPlotA:6 = @drawbuff.1 +_hgrPlotA:9 = @hgrscanh +_hgrPlotB:1 = @divmod7 +_hgrPlotC:1 = @hbmask +_hgrPlotD:1 = @curhclr +_hgrXorPlotA:1 = @hgrscanl +_hgrXorPlotA:6 = @drawbuff.1 +_hgrXorPlotA:9 = @hgrscanh +_hgrXorPlotB:1 = @divmod7 +_hgrXorPlotC:1 = @hbmask +_hgrXorPlotD:1 = @curhclr +_hgrOrPlotA:1 = @hgrscanl +_hgrOrPlotA:6 = @drawbuff.1 +_hgrOrPlotA:9 = @hgrscanh +_hgrOrPlotB:1 = @divmod7 +_hgrOrPlotC:1 = @hbmask +_hgrOrPlotD:1 = @curhclr +_hgrHLinA:1 = @hgrPlot +_hgrHLinB:1 = @hgrscanl +_hgrHLinB:6 = @drawbuff.1 +_hgrHLinB:9 = @hgrscanh +_hgrHLinC:1 = @divmod7 +_hgrHLinD:1 = @hrmask +_hgrHLinE:1 = @divmod7 +_hgrHLinF:1 = @hlmask +_hgrHLinG:1 = @curhclr.1 +_hgrHLinG:6 = @curhclr +_hgrHLinG:13 = @curhclr +_hgrHLinG:18 = @curhclr.1 +_hgrXHLinA:1 = @hgrXorPlot +_hgrXHLinB:1 = @hgrscanl +_hgrXHLinB:6 = @drawbuff.1 +_hgrXHLinB:9 = @hgrscanh +_hgrXHLinC:1 = @divmod7 +_hgrXHLinD:1 = @hrmask +_hgrXHLinE:1 = @divmod7 +_hgrXHLinF:1 = @hlmask +_hgrXHLinG:1 = @curhclr.1 +_hgrXHLinG:6 = @curhclr +_hgrXHLinG:13 = @curhclr +_hgrXHLinG:18 = @curhclr.1 +hgrVLin:1 = @divmod7 +_hgrVLinA:1 = @hbmask +_hgrVLinB:1 = @curhclr +_hgrVLinC:1 = @hgrscanl +_hgrVLinC:6 = @drawbuff.1 +_hgrVLinC:9 = @hgrscanh +hgrXorVLin:1 = @divmod7 +_hgrXVLinA:1 = @hbmask +_hgrXVLinB:1 = @curhclr +_hgrXVLinC:1 = @hgrscanl +_hgrXVLinC:6 = @drawbuff.1 +_hgrXVLinC:9 = @hgrscanh +hgrColor:7 = @hcolor +hgrColor:10 = @curhclr +hgrColor:13 = @hcolor.1 +hgrColor:16 = @curhclr.1 +_scanBLTA:1 = @hgrColor +_scanBLTB:1 = @hgrPlot +_scanBLTB:8 = @hgrOrPlot +_scanBLTC:1 = @hgrColor +_scanBLTD:1 = @hgrPlot +_scanBLTD:8 = @hgrOrPlot +done diff --git a/src/libsrc/apple/hgrsprite.pla b/src/libsrc/apple/hgrsprite.pla new file mode 100644 index 0000000..9d5f68e --- /dev/null +++ b/src/libsrc/apple/hgrsprite.pla @@ -0,0 +1,365 @@ +include "inc/cmdsys.plh" +include "inc/hgrlib.plh" +include "inc/fileio.plh" + +struc t_sprite + var s_xpos + var s_ypos + var s_undery[2] + var s_underofst[2] + byte s_undermap[2] + byte s_xcenter + byte s_ycenter + byte s_pitch + byte s_height + var s_size + var s_mask[14] + var s_map[14] + var s_under[14] +end + +var drawList[16] +var undrawList0[16] +var undrawList1[16] +var undrawList[2] = @undrawList0, @undrawList1 +byte drawpage +// +// Sprite routines +// +asm scanMask(x, y, w, srcptr)#0 +!SOURCE "vmsrc/plvmzp.inc" + LDA ESTKL+0,X ; SRC PTR + STA SRCL + LDA ESTKH+0,X + STA SRCH + LDA #$00 +- PHA + LSR + TAY + LDA (SRC),Y + AND #$80 + BEQ + + LDA #$03 ++ DEX + STA ESTKL+0,X +end +asm _scanMaskA + JSR $C000 ; HCOLOR + DEX + DEX + LDA ESTKL+5,X ; X COORDL + STA ESTKL+1,X + LDA ESTKH+5,X ; X COORDH + STA ESTKH+1,X + LDA ESTKL+4,X ; Y COORDL + STA ESTKL+0,X + LDA ESTKH+4,X ; Y COORDH + STA ESTKH+0,X +end +asm _scanMaskB + JSR $D000 ; HPLOT + INC ESTKL+3,X ; X COORDL + BNE + + INC ESTKH+3,X ; X COORDH ++ PLA + CLC + ADC #$01 + CMP ESTKL+1,X ; WIDTH + BEQ BLTDONE + PHA + LSR + TAY + LDA (SRC),Y + AND #$08 + BEQ + + LDA #$03 ++ DEX + STA ESTKL+0,X +end +asm _scanMaskC + JSR $C000 ; HCOLOR + DEX + DEX + LDA ESTKL+5,X ; X COORDL + STA ESTKL+1,X + LDA ESTKH+5,X ; X COORDH + STA ESTKH+1,X + LDA ESTKL+4,X ; Y COORDL + STA ESTKL+0,X + LDA ESTKH+4,X ; Y COORDH + STA ESTKH+0,X +end +asm _scanMaskD + JSR $D000 ; HPLOT + INC ESTKL+3,X ; X COORDL + BNE + + INC ESTKH+3,X ; X COORDH ++ PLA + CLC + ADC #$01 + CMP ESTKL+1,X ; WIDTH + BNE - +BLTDONE INX + INX + INX + INX + RTS +end +def spriteBLTMask(x, y, w, h, srcptr)#0 + word i, j + byte pitch + byte c + + pitch = (w + 1) / 2 + for j = y to y + h - 1 + scanMask(x, j, w, srcptr) +// for i = 0 to w - 1 +// c = srcptr->[i >> 1] +// if i & 1 +// hgrColor(c & $08 ?? 3 :: 0) +// else +// hgrColor(c & $80 ?? 3 :: 0) +// fin +// hgrPlot(x + i, j) +// next + srcptr = srcptr + pitch + next +end +export def spriteCompile(w, h, xcenter, ycenter, srcptr)#1 + var sprtptr, bytewidth, spritesize, i + + sprtptr = heapalloc(t_sprite) + if not sprtptr; return 0; fin + bytewidth = (w + 13) / 7 + sprtptr->s_pitch = bytewidth + spritesize = bytewidth * h + sprtptr=>s_size = spritesize + sprtptr->s_height = h + sprtptr->s_xcenter = xcenter + sprtptr->s_ycenter = ycenter + sprtptr=>s_under[0] = 0 + sprtptr=>s_under[1] = 0 + for i = 0 to 13 + sprtptr=>s_map[i] = heapalloc(spritesize) + sprtptr=>s_mask[i] = heapalloc(spritesize) + if not sprtptr=>s_map[i] or not sprtptr=>s_mask[i] + heaprelease(sprtptr) + return 0 + fin + hgrColor(7) + hgrRect(0, 0, w + 21, h - 1) + spriteBLTMask(i, 0, w, h, srcptr) + hgrCopyDst(i > 6 ?? 1 :: 0, 0, bytewidth, h, sprtptr=>s_mask[i]) + hgrColor(0) + hgrRect(0, h, w + 21, h * 2 - 1) + hgrBLT(i, h, w, h, srcptr) + hgrCopyDst(i > 6 ?? 1 :: 0, h, bytewidth, h, sprtptr=>s_map[i]) + next + return sprtptr +end +export def spriteDup(sprtsrc)#1 + var sprtdup + byte i + + sprtdup = heapalloc(t_sprite) + if not sprtdup; return 0; fin + memcpy(sprtdup, sprtsrc, t_sprite) + sprtdup=>s_under[0] = 0 + sprtdup=>s_under[1] = 0 + return sprtdup +end +export def spriteRead(filestr)#1 + var sprtptr, spritesize + byte refnum, i + + sprtptr = heapalloc(t_sprite) + if not sprtptr; return 0; fin + refnum = fileio:open(filestr) + if refnum + if fileio:read(refnum, sprtptr, t_sprite) == t_sprite + spritesize = sprtptr=>s_size + sprtptr=>s_under[0] = 0 + sprtptr=>s_under[1] = 0 + for i = 0 to 13 + sprtptr=>s_map[i] = heapalloc(spritesize) + sprtptr=>s_mask[i] = heapalloc(spritesize) + if not sprtptr=>s_map[i] or not sprtptr=>s_mask[i] + heaprelease(sprtptr) + fileio:close(refnum) + return 0 + fin + fileio:read(refnum, sprtptr=>s_map[i], spritesize) + fileio:read(refnum, sprtptr=>s_mask[i], spritesize) + next + else + heaprelease(sprtptr) + sprtptr = 0 + fin + fileio:close(refnum) + else + heaprelease(sprtptr) + sprtptr = 0 + fin + return sprtptr +end +export def spriteSave(filestr, sprtptr)#1 + var spritesize + byte refnum, i + + fileio:destroy(filestr) + if fileio:create(filestr, $06, $0000) == FILE_ERR_OK + refnum = fileio:open(filestr) + if refnum + if fileio:write(refnum, sprtptr, t_sprite) == t_sprite + spritesize = sprtptr=>s_size + for i = 0 to 13 + fileio:write(refnum, sprtptr=>s_map[i], spritesize) + fileio:write(refnum, sprtptr=>s_mask[i], spritesize) + next + fin + fileio:close(refnum) + return 0 + fin + fin + return -1 +end +export def spriteDraw(sprtptr)#0 + byte map, pitch, height + var ofst, y + + y = sprtptr=>s_ypos + ofst, map = divmod7(sprtptr=>s_xpos) + if ofst & 1 + map = map + 7 + fin + sprtptr=>s_underofst[drawpage] = ofst + sprtptr=>s_undery[drawpage] = y + pitch = sprtptr->s_pitch + height = sprtptr->s_height + if not sprtptr=>s_under[drawpage] + sprtptr=>s_under[drawpage] = heapalloc(sprtptr=>s_size) + if not sprtptr=>s_under[drawpage]; return; fin + fin + hgrCopyDst(ofst, y, pitch, height, sprtptr=>s_under[drawpage]) + hgrAndSrc( ofst, y, pitch, height, sprtptr=>s_mask[map]) + hgrXorSrc( ofst, y, pitch, height, sprtptr=>s_map[map]) +end +export def spriteUnDraw(sprtptr)#0 + if sprtptr=>s_under[drawpage] + hgrCopySrc(sprtptr=>s_underofst[drawpage], sprtptr=>s_undery[drawpage], sprtptr->s_pitch, sprtptr->s_height, sprtptr=>s_under[drawpage]) + fin +end +export def spriteDrawXor(sprtptr)#0 + byte map, pitch, height + var ofst, y + + y = sprtptr=>s_ypos + ofst, map = divmod7(sprtptr=>s_xpos) + if ofst & 1 + map = map + 7 + fin + sprtptr->s_undermap[drawpage] = map + sprtptr=>s_underofst[drawpage] = ofst + sprtptr=>s_undery[drawpage] = y + pitch = sprtptr->s_pitch + height = sprtptr->s_height + hgrXorSrc( ofst, y, pitch, height, sprtptr=>s_map[map]) +end +export def spriteUnDrawXor(sprtptr)#0 + hgrXorSrc(sprtptr=>s_underofst[drawpage], sprtptr=>s_undery[drawpage], sprtptr->s_pitch, sprtptr->s_height, sprtptr=>s_map[sprtptr->s_undermap[drawpage]]) +end +export def spritePos(x, y, sprtptr)#0 + sprtptr=>s_ypos = y - sprtptr->s_ycenter + sprtptr=>s_xpos = x - sprtptr->s_xcenter +end +export def spritePosIndex(x, y, i)#0 + i = i & 15 + if drawList[i] + drawList[i]=>s_ypos = y - drawList[i]->s_ycenter + drawList[i]=>s_xpos = x - drawList[i]->s_xcenter + fin +end +export def spriteUnDrawList#0 + byte i + var undrawptr + + undrawptr = undrawList[drawpage] + for i = 15 downto 0 + if undrawptr=>[i] + spriteUnDraw(undrawptr=>[i]) + undrawptr=>[i] = 0 + fin + next +end +export def spriteDrawList#0 + byte i + var undrawptr + + undrawptr = undrawList[drawpage] + for i = 15 downto 0 + if undrawptr=>[i] + spriteUnDraw(undrawptr=>[i]) + fin + next + for i = 0 to 15 + if drawList[i] + spriteDraw(drawList[i]) + fin + next + memcpy(undrawptr, @drawList, 16*2) +end +export def spriteUnDrawXorList#0 + byte i + var undrawptr + + undrawptr = undrawList[drawpage] + for i = 0 to 15 + if undrawptr=>[i] + spriteUnDrawXor(undrawptr=>[i]) + undrawptr=>[i] = 0 + fin + next +end +export def spriteDrawXorList#0 + byte i + var undrawptr + + undrawptr = undrawList[drawpage] + for i = 0 to 15 + if undrawptr=>[i] + spriteUnDrawXor(undrawptr=>[i]) + fin + if drawList[i] + spriteDrawXor(drawList[i]) + fin + next + memcpy(undrawptr, @drawList, 16*2) +end +export def spriteAdd(i, sprtptr)#1 + var sprtprev + + i = i & 15 + sprtprev = drawList[i] + drawList[i] = sprtptr + return sprtprev +end +export def spriteDel(i)#1 + var sprtprev + + i = i & 15 + sprtprev = drawList[i] + drawList[i] = 0 + return sprtprev +end +export def spriteDrawBuf(page)#1 + drawpage = page & 1 + return drawpage +end +// +// Assembly fixups +// +_scanMaskA:1 = @hgrColor +_scanMaskB:1 = @hgrPlot +_scanMaskC:1 = @hgrColor +_scanMaskD:1 = @hgrPlot +done diff --git a/src/libsrc/apple/hgrtile.pla b/src/libsrc/apple/hgrtile.pla new file mode 100644 index 0000000..a02cfab --- /dev/null +++ b/src/libsrc/apple/hgrtile.pla @@ -0,0 +1,435 @@ +include "inc/cmdsys.plh" +// +// Hardware addresses +// +const showgraphics = $C050 +const showtext = $C051 +const showfull = $C052 +const showmix = $C053 +const showpage1 = $C054 +const showpage2 = $C055 +const showlores = $C056 +const showhires = $C057 +const keyboard = $C000 +const keystrobe = $C010 +const txt1 = $0400 +const txt2 = $0800 +const hgr1 = $2000 +const hgr2 = $4000 +const page1 = 0 +const page2 = 1 + +word txtbuff[] = txt1, txt2 +word hgrbuff[] = hgr1, hgr2 +// +// Screen tile scanline addresses. +// +word[] rowaddr = $0000,$0080,$0100,$0180,$0200,$0280,$0300,$0380 +word = $0028,$00A8,$0128,$01A8,$0228,$02A8,$0328,$03A8 +word = $0050,$00D0,$0150,$01D0,$0250,$02D0,$0350,$03D0 +byte[] scanbttml = $00,$80,$00,$80,$00,$80,$00,$80 +byte = $28,$A8,$28,$A8,$28,$A8,$28,$A8 +byte = $50,$D0,$50,$D0,$50,$D0,$50,$D0 +byte[] scanbttmh = $1C,$1C,$1D,$1D,$1E,$1E,$1F,$1F +byte = $1C,$1C,$1D,$1D,$1E,$1E,$1F,$1F +byte = $1C,$1C,$1D,$1D,$1E,$1E,$1F,$1F + +byte hbmask = $81,$82,$84,$88,$90,$A0,$C0 +word hcolor[] = $0000,$552A,$2A55,$7F7F,$8080,$D5AA,$AAD5,$FFFF +byte drawpage = 0 +word drawbuff = hgr1 + +asm tileInc#0 +!SOURCE "vmsrc/plvmzp.inc" +CURSH = $24 +CURSV = $25 +GBASL = $26 +GBASH = $27 +GBASE = GBASL +TBASL = $28 +TBASH = $29 +TBASE = TBASL +TBAS2L = $2A +TBAS2H = $2B +TBAS2E = TBAS2L +end +//export def tileDraw(x, y, tileptr)#0 +// var scrnptr +// +// scrnptr = (scanaddr[y] | drawbuff) + x +// scrnptr->[$1C00] = tileptr->[7] +// scrnptr->[$1800] = tileptr->[6] +// scrnptr->[$1400] = tileptr->[5] +// scrnptr->[$1000] = tileptr->[4] +// scrnptr->[$0C00] = tileptr->[3] +// scrnptr->[$0800] = tileptr->[2] +// scrnptr->[$0400] = tileptr->[1] +// scrnptr->[$0000] = tileptr->[0] +//end +export asm tileDraw(x, y, tileptr)#0 + LDA ESTKL+0,X ; TILEPTRL + STA SRCL + LDA ESTKH+0,X ; TILEPTRH + STA SRCH + LDY ESTKL+1,X ; Y COORD + LDA ESTKL+2,X ; X COORD + CLC +end +asm _tileDraw + ADC $1000,Y ; SCANBTTML + STA ESTKL+0,X ; USE ESTK AS POINTER + LDA $3001 ; DRAWBUFFH + ADC $2000,Y ; SCANBTTMH + STA ESTKL+1,X + LDY #$07 ; DRAW BOTTOM UP + SEC +- LDA (SRC),Y + STA (ESTKL,X) + LDA ESTKL+1,X + SBC #$04 + STA ESTKL+1,X + DEY + BNE - + LDA (SRC),Y + STA (ESTKL,X) + INX + INX + INX + RTS +end +//export def tileXorDraw(x, y, tileptr)#0 +// var scrnptr +// +// scrnptr = (scanaddr[y] | drawbuff) + x +// scrnptr->[$1C00] = tileptr->[7] +// scrnptr->[$1800] = tileptr->[6] +// scrnptr->[$1400] = tileptr->[5] +// scrnptr->[$1000] = tileptr->[4] +// scrnptr->[$0C00] = tileptr->[3] +// scrnptr->[$0800] = tileptr->[2] +// scrnptr->[$0400] = tileptr->[1] +// scrnptr->[$0000] = tileptr->[0] +//end +export asm tileXorDraw(x, y, tileptr)#0 + LDA ESTKL+0,X ; TILEPTRL + STA SRCL + LDA ESTKH+0,X ; TILEPTRH + STA SRCH + LDY ESTKL+1,X ; Y COORD + LDA ESTKL+2,X ; X COORD + CLC +end +asm _tileXDraw + ADC $1000,Y ; SCANBTTML + STA ESTKL+0,X ; USE ESTK AS POINTER + LDA $3001 ; DRAWBUFFH + ADC $2000,Y ; SCANBTTMH + STA ESTKL+1,X + LDY #$07 ; DRAW BOTTOM UP + SEC +- LDA (SRC),Y + EOR (ESTKL,X) + STA (ESTKL,X) + LDA ESTKL+1,X + SBC #$04 + STA ESTKL+1,X + DEY + BNE - + LDA (SRC),Y + EOR (ESTKL,X) + STA (ESTKL,X) + INX + INX + INX + RTS +end +//export def tileOrDraw(x, y, tileptr)#0 +// var scrnptr +// +// scrnptr = (scanaddr[y] | drawbuff) + x +// scrnptr->[$1C00] = tileptr->[7] +// scrnptr->[$1800] = tileptr->[6] +// scrnptr->[$1400] = tileptr->[5] +// scrnptr->[$1000] = tileptr->[4] +// scrnptr->[$0C00] = tileptr->[3] +// scrnptr->[$0800] = tileptr->[2] +// scrnptr->[$0400] = tileptr->[1] +// scrnptr->[$0000] = tileptr->[0] +//end +export asm tileOrDraw(x, y, tileptr)#0 + LDA ESTKL+0,X ; TILEPTRL + STA SRCL + LDA ESTKH+0,X ; TILEPTRH + STA SRCH + LDY ESTKL+1,X ; Y COORD + LDA ESTKL+2,X ; X COORD + CLC +end +asm _tileODraw + ADC $1000,Y ; SCANBTTML + STA ESTKL+0,X ; USE ESTK AS POINTER + LDA $3001 ; DRAWBUFFH + ADC $2000,Y ; SCANBTTMH + STA ESTKL+1,X + LDY #$07 ; DRAW BOTTOM UP + SEC +- LDA (SRC),Y + ORA (ESTKL,X) + STA (ESTKL,X) + LDA ESTKL+1,X + SBC #$04 + STA ESTKL+1,X + DEY + BNE - + LDA (SRC),Y + ORA (ESTKL,X) + STA (ESTKL,X) + INX + INX + INX + RTS +end +//export def tileAndDraw(x, y, tileptr)#0 +// var scrnptr +// +// scrnptr = (scanaddr[y] | drawbuff) + x +// scrnptr->[$1C00] = tileptr->[7] +// scrnptr->[$1800] = tileptr->[6] +// scrnptr->[$1400] = tileptr->[5] +// scrnptr->[$1000] = tileptr->[4] +// scrnptr->[$0C00] = tileptr->[3] +// scrnptr->[$0800] = tileptr->[2] +// scrnptr->[$0400] = tileptr->[1] +// scrnptr->[$0000] = tileptr->[0] +//end +export asm tileAndDraw(x, y, tileptr)#0 + LDA ESTKL+0,X ; TILEPTRL + STA SRCL + LDA ESTKH+0,X ; TILEPTRH + STA SRCH + LDY ESTKL+1,X ; Y COORD + LDA ESTKL+2,X ; X COORD + CLC +end +asm _tileADraw + ADC $1000,Y ; SCANBTTML + STA ESTKL+0,X ; USE ESTK AS POINTER + LDA $3001 ; DRAWBUFFH + ADC $2000,Y ; SCANBTTMH + STA ESTKL+1,X + LDY #$07 ; DRAW BOTTOM UP + SEC +- LDA (SRC),Y + AND (ESTKL,X) + STA (ESTKL,X) + LDA ESTKL+1,X + SBC #$04 + STA ESTKL+1,X + DEY + BNE - + LDA (SRC),Y + AND (ESTKL,X) + STA (ESTKL,X) + INX + INX + INX + RTS +end +//export def tileDrawStr(x, y, strptr, strlen, tileset)#0 +// while strlen +// tileDraw(x, y, tileset + ^strptr * 8) +// x++ +// strptr++ +// strlen-- +// loop +//end +export asm tileDrawStr(x, y, strptr, strlen, tileset)#0 + LDA ESTKL+0,X ; TILESETPTRL + STA DSTL + LDA ESTKH+0,X ; TILESETPTRH + STA DSTH + LDA ESTKL+2,X ; STRPTRL + STA TMPL + LDA ESTKH+2,X ; STRPTRH + STA TMPH + LDY ESTKL+3,X ; Y COORD + LDA ESTKL+4,X ; X COORD + CLC +end +asm _tileDSa + ADC $1000,Y ; SCANBTTML + STA $D000 ; SELF MODIFY LOOP + STA $D001 + STA $D002 + STA $D003 + STA $D004 + STA $D005 + STA $D006 + STA $D007 +end +asm _tileDSb + LDA $3001 ; DRAWBUFFH + ADC $2000,Y ; SCANBTTMH + STA $D008 ; SELF MODIFY LOOP + SEC + SBC #$04 + STA $D009 + SBC #$04 + STA $D00A + SBC #$04 + STA $D00B + SBC #$04 + STA $D00C + SBC #$04 + STA $D00D + SBC #$04 + STA $D00E + SBC #$04 + STA $D00F + LDA ESTKL+1,X ; STRLEN + STX IPY + TAX ; DRAW RIGHT TO LEFT + BEQ + + DEX + LDY #$00 +- STY SRCH + TXA + TAY + LDA (TMP),Y ; TILE INDEX * 8 + ASL + ROL SRCH + ASL + ROL SRCH + ASL + ROL SRCH +; CLC ; CARRY IS CLEAR FROM ABOVE + ADC DSTL ; ADD TO TILESETPTR + STA SRCL + LDA SRCH + ADC DSTH + STA SRCH + LDY #$07 ; DRAW BOTTOM UP +end +asm _tileDSc + LDA (SRC),Y + STA $4000,X + DEY + LDA (SRC),Y + STA $4000,X + DEY + LDA (SRC),Y + STA $4000,X + DEY + LDA (SRC),Y + STA $4000,X + DEY + LDA (SRC),Y + STA $4000,X + DEY + LDA (SRC),Y + STA $4000,X + DEY + LDA (SRC),Y + STA $4000,X + DEY + LDA (SRC),Y + STA $4000,X + DEX + BPL - + LDX IPY ++ INX + INX + INX + INX + INX + RTS +end +export def tileFromText(txtpage, tileset)#0 + byte y + word txtptr + + txtptr = txtbuff[txtpage & 1] + for y = 0 to 23 + tileDrawStr(0, y, rowaddr[y] | txtptr, 40, tileset) + next +end +export def tileMode(mode)#1 + if mode + // + // Set HGR mode + // + memset(hgr1, 0, $2000) // Clear HGR page 1 + ^showpage1 + ^showfull + ^showhires + ^showgraphics + drawpage = 0 + drawbuff = hgr1 + return 0 + fin + // + // Show text mode + // + ^showpage1 + ^showtext + return 0 +end +export def tileClear#0 + memset(drawbuff, $0000, drawbuff) // Clear current HGR page +end +// +// Set display page, return other page +// +export def tileShow(page)#1 + page = page & 1 + ^(showpage1 + page) + return page ^ 1 +end +export def tileSwap#1 + ^(showpage1 + drawpage) + drawpage = drawpage ^ 1 + drawbuff = hgrbuff[drawpage] + return drawpage +end +export def tileDrawBuf(page)#1 + drawpage = page & 1 + drawbuff = hgrbuff[drawpage] + return drawpage +end +// +// Assembly fixups +// +_tileDraw:1 = @scanbttml +_tileDraw:6 = @drawbuff.1 +_tileDraw:9 = @scanbttmh +_tileXDraw:1 = @scanbttml +_tileXDraw:6 = @drawbuff.1 +_tileXDraw:9 = @scanbttmh +_tileODraw:1 = @scanbttml +_tileODraw:6 = @drawbuff.1 +_tileODraw:9 = @scanbttmh +_tileADraw:1 = @scanbttml +_tileADraw:6 = @drawbuff.1 +_tileADraw:9 = @scanbttmh +_tileDSa:1 = @scanbttml +_tileDSa:4 = @_tileDSc.3 +_tileDSa:7 = @_tileDSc.9 +_tileDSa:10 = @_tileDSc.15 +_tileDSa:13 = @_tileDSc.21 +_tileDSa:16 = @_tileDSc.27 +_tileDSa:19 = @_tileDSc.33 +_tileDSa:22 = @_tileDSc.39 +_tileDSa:25 = @_tileDSc.45 +_tileDSa:28 = @_tileDSc.51 +_tileDSb:1 = @drawbuff.1 +_tileDSb:4 = @scanbttmh +_tileDSb:7 = @_tileDSc.4 +_tileDSb:13 = @_tileDSc.10 +_tileDSb:18 = @_tileDSc.16 +_tileDSb:23 = @_tileDSc.22 +_tileDSb:28 = @_tileDSc.28 +_tileDSb:33 = @_tileDSc.34 +_tileDSb:38 = @_tileDSc.40 +_tileDSb:43 = @_tileDSc.46 +done + diff --git a/src/libsrc/apple/jit.pla b/src/libsrc/apple/jit.pla index 263d645..f0bd2e9 100644 --- a/src/libsrc/apple/jit.pla +++ b/src/libsrc/apple/jit.pla @@ -49,7 +49,7 @@ if *jitcomp return 0 fin *jitcomp = @compiler -cmdsys.jitcount = 44 +cmdsys.jitcount = 36 cmdsys.jitsize = 96 puts("JITC enabled\n") return modkeep diff --git a/src/libsrc/apple/jit16.pla b/src/libsrc/apple/jit16.pla index cea991c..34e9fc2 100644 --- a/src/libsrc/apple/jit16.pla +++ b/src/libsrc/apple/jit16.pla @@ -50,7 +50,7 @@ end // Identify hardware addresses for certain byte sized access operations // def is_hwaddr(addr) - return addr >= $C000 and addr < $C100 + return isuge(addr, $C000) and isult(addr, $C100) end include "libsrc/jit16core.pla" // @@ -60,7 +60,7 @@ if *jitcomp return 0 fin *jitcomp = @compiler -cmdsys.jitcount = 44 +cmdsys.jitcount = 32 cmdsys.jitsize = 96 puts("16-bit VM/JITC enabled\n") return modkeep diff --git a/src/libsrc/apple/matchfiles.pla b/src/libsrc/apple/matchfiles.pla new file mode 100644 index 0000000..69c2afe --- /dev/null +++ b/src/libsrc/apple/matchfiles.pla @@ -0,0 +1,122 @@ +include "inc/cmdsys.plh" +include "inc/fileio.plh" + +var dirbuf +// +// Match next section of source and expression +// +def matchNext(src, srcofst, exp, expofst) + if ^exp >= expofst + when exp->[expofst] + is '*' // Multi-char wildcard + if matchNext(src, srcofst, exp, expofst + 1) // Match zero wild chars + return TRUE + elsif ^src >= srcofst and matchNext(src, srcofst + 1, exp, expofst) // Match more wild chars + return TRUE + fin + is '?' // Single char wildcard + if ^src >= srcofst + return matchNext(src, srcofst + 1, exp, expofst + 1) + fin + return FALSE + otherwise // verbatim match + if ^src >= srcofst and src->[srcofst] == exp->[expofst] + return matchNext(src, srcofst + 1, exp, expofst + 1) + fin + return FALSE + wend + fin + return ^src < srcofst and ^exp < expofst // Return TRUE if at the end of both +end +// +// Start off matching process +// +export def matchName(src, exp)#1 + // + // Match on empty wildcard name (same as '*') + // + if not ^exp + return TRUE + fin + return matchNext(src, 1, exp, 1) +end +export def matchList(pathstr, exp)#2 + byte refnum + char[64] curpath + var firstblk, entrylen, entriesblk, i, entry, filecnt, entrylist, entryptr, entrycnt + + if not dirbuf + dirbuf = heapallocalign(512, 8, 0) + fin + if not ^pathstr + fileio:getpfx(@curpath) + pathstr = @curpath + fin + if pathstr->[^pathstr] <> '/' // Make sure path ends with a '/' + ^pathstr++ + pathstr->[^pathstr] = '/' + fin + entrylist = 0 + entrycnt = 0 + filecnt = 0 + firstblk = 1 + refnum = fileio:open(pathstr) + repeat + if fileio:read(refnum, dirbuf, 512) == 512 + // + // Skip block pointers + // + entry = dirbuf + 4 + if firstblk + // + // Pull out revelant details from the first block + // + entrylen = dirbuf->$23 + entriesblk = dirbuf->$24 + filecnt = dirbuf=>$25 + entry = entry + entrylen + fin + for i = firstblk to entriesblk + // + // Copy directory entry details + // + ^entry = ^entry & $0F + if ^entry + // + // Match wildcard filename + // + if matchName(entry, exp) + entryptr = heapalloc(t_fileentry) + memcpy(entryptr, entry, t_fileentry) + entrycnt++ + if not entrylist + entrylist = entryptr + fin + fin + filecnt-- + fin + entry = entry + entrylen + next + firstblk = 0 + fin + until filecnt == 0 + fileio:close(refnum) + return entrylist, entrycnt +end +// +// Is this a wildcard name? +// +export def isWildName(exp)#1 + byte i + + if ^exp + for i = 1 to ^exp + if exp->[i] == '*' or exp->[i] == '?' + return TRUE + fin + next + fin + return FALSE +end +done + diff --git a/src/libsrc/apple/mouse.pla b/src/libsrc/apple/mouse.pla index 6d5193d..5472b8d 100644 --- a/src/libsrc/apple/mouse.pla +++ b/src/libsrc/apple/mouse.pla @@ -270,7 +270,7 @@ CHKSIG: LDY #$05 LDA (TMPTR),Y CMP #$01 BNE :+ - LDY #$0C + INY TXA ; LOOK FOR MATCHING ID CMP (TMPTR),Y BNE :+ @@ -283,7 +283,6 @@ CHKSIG: LDY #$05 LDA TMPTR+1 CMP #$C8 BCC CHKSIG - SEC RTS ;* diff --git a/src/libsrc/apple/sndseq.pla b/src/libsrc/apple/sndseq.pla index 152d951..b070ece 100755 --- a/src/libsrc/apple/sndseq.pla +++ b/src/libsrc/apple/sndseq.pla @@ -305,7 +305,7 @@ TONELP SBC #$01 ; 2 ;+4 = 11 (from BNE above) +++ BIT $C000 ; 4 - BMI TONEXIT ; 2 + NOP ; 2 BPL TONELP ; 3 ;--- ;+9 = 20 diff --git a/src/libsrc/dhcp.pla b/src/libsrc/dhcp.pla index 2bc94d6..843bb36 100644 --- a/src/libsrc/dhcp.pla +++ b/src/libsrc/dhcp.pla @@ -3,6 +3,7 @@ // include "inc/cmdsys.plh" include "inc/inet.plh" +sysflags nojitc // No need to JITC this temp loaded module // // Needed to init subnet // diff --git a/src/libsrc/int32.pla b/src/libsrc/int32.pla new file mode 100644 index 0000000..82a3e80 --- /dev/null +++ b/src/libsrc/int32.pla @@ -0,0 +1,682 @@ +// +// 32 bit integer math routines +// +include "inc/cmdsys.plh" +const t_i32 = 4 +// +// Include zero page definitions +// +asm int32Inc + !SOURCE "vmsrc/plvmzp.inc" +ACCUM32 = DSTH+1 +DVSIGN = TMP+3 +end +export asm zero32#0 + LDA #$00 + STA ACCUM32+0 + STA ACCUM32+1 + STA ACCUM32+2 + STA ACCUM32+3 + RTS +end +export asm zext16to32#0 + LDA #$00 + STA ACCUM32+2 + STA ACCUM32+3 + RTS +end +export asm neg32#0 + LDA #$00 + SEC + SBC ACCUM32+0 + STA ACCUM32+0 + LDA #$00 + SBC ACCUM32+1 + STA ACCUM32+1 + LDA #$00 + SBC ACCUM32+2 + STA ACCUM32+2 + LDA #$00 + SBC ACCUM32+3 + STA ACCUM32+3 + RTS +end +export asm load32(i32ptr)#0 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$00 + LDA (TMP),Y + STA ACCUM32+0 + INY + LDA (TMP),Y + STA ACCUM32+1 + INY + LDA (TMP),Y + STA ACCUM32+2 + INY + LDA (TMP),Y + STA ACCUM32+3 + INX + RTS +end +export asm loadi16(imm16)#0 + LDY #$00 + LDA ESTKL+0,X ; IMM16L + STA ACCUM32+0 + LDA ESTKH+0,X ; IMM16H + STA ACCUM32+1 + BPL + ; SIGN EXTEND + DEY ++ STY ACCUM32+2 + STY ACCUM32+3 + INX + RTS +end +export asm store32(i32ptr)#0 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$00 + LDA ACCUM32+0 + STA (TMP),Y + INY + LDA ACCUM32+1 + STA (TMP),Y + INY + LDA ACCUM32+2 + STA (TMP),Y + INY + LDA ACCUM32+3 + STA (TMP),Y + INX + RTS +end +export asm add32(i32ptr)#0 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$00 + LDA (TMP),Y + CLC + ADC ACCUM32+0 + STA ACCUM32+0 + INY + LDA (TMP),Y + ADC ACCUM32+1 + STA ACCUM32+1 + INY + LDA (TMP),Y + ADC ACCUM32+2 + STA ACCUM32+2 + INY + LDA (TMP),Y + ADC ACCUM32+3 + STA ACCUM32+3 + INX + RTS +end +export asm addi16(imm16)#0 + LDY #$00 + LDA ESTKL+0,X ; IMM16L + CLC + ADC ACCUM32+0 + STA ACCUM32+0 + LDA ESTKH+0,X ; IMM16H + BPL + + DEY ++ ADC ACCUM32+1 + STA ACCUM32+1 + TYA + ADC ACCUM32+2 + STA ACCUM32+2 + TYA + ADC ACCUM32+3 + STA ACCUM32+3 + INX + RTS +end +export asm sub32(i32ptr)#0 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$03 +- LDA (TMP),Y + STA SRC,Y + DEY + BPL - + BMI _SUB +end +export asm subi16(imm16)#0 + LDY #$00 + LDA ESTKL+0,X ; IMM16L + STA SRC+0 + LDA ESTKH+0,X ; IMM16H + STA SRC+1 + BPL + ; SIGN EXTEND + DEY ++ STY SRC+2 + STY SRC+3 +_SUB LDA ACCUM32+0 + SEC + SBC SRC+0 + STA ACCUM32+0 + LDA ACCUM32+1 + SBC SRC+1 + STA ACCUM32+1 + LDA ACCUM32+2 + SBC SRC+2 + STA ACCUM32+2 + LDA ACCUM32+3 + SBC SRC+3 + STA ACCUM32+3 + INX + RTS +end +export asm shl32(imm8)#0 + LDA ESTKL+0,X ; IMM8 + AND #$1F + CMP #16 + BCC + + LDY ACCUM32+1 + STY ACCUM32+3 + LDY ACCUM32+0 + STY ACCUM32+2 + LDY #$00 + STY ACCUM32+1 + STY ACCUM32+0 + SBC #16 ++ CMP #8 + BCC + + LDY ACCUM32+2 + STY ACCUM32+3 + LDY ACCUM32+1 + STY ACCUM32+2 + LDY ACCUM32+0 + STY ACCUM32+1 + LDY #$00 + STY ACCUM32+0 + SBC #8 ++ TAY + BEQ ++ +- ASL ACCUM32+0 + ROL ACCUM32+1 + ROL ACCUM32+2 + ROL ACCUM32+3 + DEY + BNE - +++ INX + RTS +end +export asm shr32(imm8)#0 + LDA ESTKL+0,X ; IMM8 + AND #$1F + BEQ + + TAY + LDA #$80 +- CMP ACCUM32 + ROR ACCUM32+3 + ROR ACCUM32+2 + ROR ACCUM32+1 + ROR ACCUM32+0 + DEY + BNE - ++ INX + RTS +end +export asm mul32(i32ptr)#0 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$03 +- LDA (TMP),Y + STA SRC,Y + DEY + BPL - + INY + BEQ _MUL +end +export asm muli16(imm16)#0 + LDY #$00 + LDA ESTKL+0,X ; IMM16L + STA SRC+0 + LDA ESTKH+0,X ; IMM16H + STA SRC+1 + BPL + ; SIGN EXTEND + DEY ++ STY SRC+2 + STY SRC+3 + LDY #$00 +_MUL LDA ACCUM32+0 + STA ESTKL-1,X + LDA ACCUM32+1 + STA ESTKH-1,X + LDA ACCUM32+2 + STA ESTKL+0,X + LDA ACCUM32+3 + STA ESTKH+0,X + STY ACCUM32+0 + STY ACCUM32+1 + STY ACCUM32+2 + STY ACCUM32+3 + LDY #$03 + LDA #$80 + STA TMPL +- AND SRC,Y + BEQ + + CLC + LDA ESTKL-1,X + ADC ACCUM32+0 + STA ACCUM32+0 + LDA ESTKH-1,X + ADC ACCUM32+1 + STA ACCUM32+1 + LDA ESTKL+0,X + ADC ACCUM32+2 + STA ACCUM32+2 + LDA ESTKH+0,X + ADC ACCUM32+3 + STA ACCUM32+3 ++ LSR TMPL + BCC + + DEY + BMI ++ + ROR TMPL ++ ASL ACCUM32+0 + ROL ACCUM32+1 + ROL ACCUM32+2 + ROL ACCUM32+3 + LDA TMPL + BNE - +++ INX + RTS +end +export asm div32(i32ptr)#2 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$03 ; DVSR = SRC..SRC+3 + LDA (TMP),Y + BMI + + STA SRC+3 + DEY +- LDA (TMP),Y + STA SRC,Y + DEY + BPL - + INY + BEQ _DIV ++ SEC +- LDA #$00 + SBC (TMP),Y + STA SRC,Y + DEY + BPL - + LDY #$01 + BNE _DIV +end +export asm divi16(imm16)#2 + LDY #$00 ; DVSR = SRC..SRC+3 + STY SRC+2 + STY SRC+3 + LDA ESTKH+0,X ; IMM16H + BPL + + TYA ; DVSR IS NEG + SEC + SBC ESTKL+0,X ; IMM16L + STA SRC+0 + TYA + SBC ESTKH+0,X ; IMM16L + STA SRC+1 + INY + BNE _DIV ++ STA SRC+1 + LDA ESTKL+0,X ; IMM16L + STA SRC+0 +_DIV STY DVSIGN ; LSB = SIGN OF DVSR + DEX ; REMNDR = ESTK..ESTK+1 + LDY #$00 + STY ESTKL+0,X + STY ESTKH+0,X + STY ESTKL+1,X + STY ESTKH+1,X + LDA SRC+0 ; DIVIDE BY 0? + ORA SRC+1 + ORA SRC+2 + ORA SRC+3 + BNE + + STA ACCUM32+0 ; SET TO 0 AND EXIT + STA ACCUM32+1 + STA ACCUM32+2 + STA ACCUM32+3 +- RTS ++ LDA ACCUM32+0 ; DIVIDE 0? + ORA ACCUM32+1 + ORA ACCUM32+2 + ORA ACCUM32+3 + BEQ - + LDA ACCUM32+3 ; DVDND = ACCUM32 + BPL + + LDA #$81 ; DVDND IS NEG + CLC + ADC DVSIGN + STA DVSIGN + TYA + SEC + SBC ACCUM32+0 + STA ACCUM32+0 + TYA + SBC ACCUM32+1 + STA ACCUM32+1 + TYA + SBC ACCUM32+2 + STA ACCUM32+2 + TYA + SBC ACCUM32+3 + STA ACCUM32+3 ++ LDY #$21 ; #BITS+1 +- ASL ACCUM32+0 ; SKIP DVDND LEADING 0 BITS + ROL ACCUM32+1 + ROL ACCUM32+2 + ROL ACCUM32+3 + DEY + BCC - +- ROL ESTKL+0,X ; REMNDR + ROL ESTKH+0,X + ROL ESTKL+1,X + ROL ESTKH+1,X + LDA ESTKL+0,X ; REMNDR + CMP SRC+0 ; DVSR + LDA ESTKH+0,X ; COMPARE + SBC SRC+1 + LDA ESTKL+1,X + SBC SRC+2 + LDA ESTKH+1,X + SBC SRC+3 + BCC + ; IS LESS THAN? + STA ESTKH+1,X + LDA ESTKL+0,X ; REMNDR + SBC SRC+0 ; DVSR + STA ESTKL+0,X ; SUBTRACT + LDA ESTKH+0,X + SBC SRC+1 + STA ESTKH+0,X + LDA ESTKL+1,X + SBC SRC+2 + STA ESTKL+1,X + SEC ++ ROL ACCUM32+0 ; DVDND + ROL ACCUM32+1 ; ROTATE IN RESULT + ROL ACCUM32+2 + ROL ACCUM32+3 + DEY + BNE - + LDA DVSIGN ; SET SIGNS OF RESULTS + BPL + + TYA + SEC + SBC ESTKL+0,X + STA ESTKL+0,X + TYA + SBC ESTKH+0,X + STA ESTKH+0,X + TYA + SBC ESTKL+1,X + STA ESTKL+1,X + TYA + SBC ESTKH+1,X + STA ESTKH+1,X + LDA DVSIGN ++ LSR + BCC + + TYA + SBC ACCUM32+0 + STA ACCUM32+0 + TYA + SBC ACCUM32+1 + STA ACCUM32+1 + TYA + SBC ACCUM32+2 + STA ACCUM32+2 + TYA + SBC ACCUM32+3 + STA ACCUM32+3 ++ RTS +end +export asm iseq32(i32ptr)#1 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$03 +- LDA (TMP),Y + STA SRC,Y + DEY + BPL - + INY + BEQ _ISEQ +end +export asm iseqi16(imm16)#1 + LDY #$00 + LDA ESTKL+0,X ; IMM16L + STA SRC+0 + LDA ESTKH+0,X ; IMM16H + STA SRC+1 + BPL + ; SIGN EXTEND + DEY ++ STY SRC+2 + STY SRC+3 + LDY #$00 +_ISEQ LDA ACCUM32+0 + CMP SRC+0 + BNE + + LDA ACCUM32+1 + CMP SRC+1 + BNE + + LDA ACCUM32+2 + CMP SRC+2 + BNE + + LDA ACCUM32+3 + CMP SRC+3 + BNE + + DEY ++ STY ESTKL+0,X + STY ESTKH+0,X + RTS +end +export asm isge32(i32ptr)#1 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$03 +- LDA (TMP),Y + STA SRC,Y + DEY + BPL - + INY + BEQ _ISGE +end +export asm isgei16(imm16)#1 + LDY #$00 + LDA ESTKL+0,X ; IMM16L + STA SRC+0 + LDA ESTKH+0,X ; IMM16H + STA SRC+1 + BPL + ; SIGN EXTEND + DEY ++ STY SRC+2 + STY SRC+3 + LDY #$00 +_ISGE LDA ACCUM32+0 + CMP SRC+0 + LDA ACCUM32+1 + SBC SRC+1 + LDA ACCUM32+2 + SBC SRC+2 + LDA ACCUM32+3 + SBC SRC+3 + BVC + + EOR #$80 ++ BMI + + DEY ++ STY ESTKL+0,X + STY ESTKH+0,X + RTS +end +export asm isle32(i32ptr)#1 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$03 +- LDA (TMP),Y + STA SRC,Y + DEY + BPL - + INY + BEQ _ISLE +end +export asm islei16(imm16)#1 + LDY #$00 + LDA ESTKL+0,X ; IMM16L + STA SRC+0 + LDA ESTKH+0,X ; IMM16H + STA SRC+1 + BPL + ; SIGN EXTEND + DEY ++ STY SRC+2 + STY SRC+3 + LDY #$00 +_ISLE LDA SRC+0 + CMP ACCUM32+0 + LDA SRC+1 + SBC ACCUM32+1 + LDA SRC+2 + SBC ACCUM32+2 + LDA SRC+3 + SBC ACCUM32+3 + BVC + + EOR #$80 ++ BMI + + DEY ++ STY ESTKL+0,X + STY ESTKH+0,X + RTS +end +export asm isgt32(i32ptr)#1 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$03 +- LDA (TMP),Y + STA SRC,Y + DEY + BPL - + INY + BEQ _ISGT +end +export asm isgti16(imm16)#1 + LDY #$00 + LDA ESTKL+0,X ; IMM16L + STA SRC+0 + LDA ESTKH+0,X ; IMM16H + STA SRC+1 + BPL + ; SIGN EXTEND + DEY ++ STY SRC+2 + STY SRC+3 + LDY #$00 +_ISGT LDA SRC+0 + CMP ACCUM32+0 + LDA SRC+1 + SBC ACCUM32+1 + LDA SRC+2 + SBC ACCUM32+2 + LDA SRC+3 + SBC ACCUM32+3 + BVC + + EOR #$80 ++ BPL + + DEY ++ STY ESTKL+0,X + STY ESTKH+0,X + RTS +end +export asm islt32(i32ptr)#1 + LDA ESTKL+0,X ; I32PTR + STA TMPL + LDA ESTKH+0,X ; I32PTR + STA TMPH + LDY #$03 +- LDA (TMP),Y + STA SRC,Y + DEY + BPL - + INY + BEQ _ISLT +end +export asm islti16(imm16)#1 + LDY #$00 + LDA ESTKL+0,X ; IMM16L + STA SRC+0 + LDA ESTKH+0,X ; IMM16H + STA SRC+1 + BPL + ; SIGN EXTEND + DEY ++ STY SRC+2 + STY SRC+3 + LDY #$00 +_ISLT LDA ACCUM32+0 + CMP SRC+0 + LDA ACCUM32+1 + SBC SRC+1 + LDA ACCUM32+2 + SBC SRC+2 + LDA ACCUM32+3 + SBC SRC+3 + BVC + + EOR #$80 ++ BPL + + DEY ++ STY ESTKL+0,X + STY ESTKH+0,X + RTS +end +export def i32tos(i32ptr, strptr)#1 + res[t_i32] save + word iptr, rem + char[12] istr + + iptr = @istr.11 + store32(@save) + load32(i32ptr) + if i32ptr->3 & $80 + neg32() + putc('-') + fin + repeat + drop, rem = divi16(10) // Only care about LSW of remainder + ^iptr = rem + '0' + iptr-- + until iseqi16(0) + ^iptr = @istr.11 - iptr + strcpy(strptr, iptr) + load32(@save) + return strptr +end +export def puti32(i32ptr)#0 + char[12] i32str + + puts(i32tos(i32ptr, @i32str)) +end + +done + diff --git a/src/libsrc/jit16core.pla b/src/libsrc/jit16core.pla index bb867c3..c036841 100644 --- a/src/libsrc/jit16core.pla +++ b/src/libsrc/jit16core.pla @@ -10,15 +10,13 @@ def compiler(defptr)#0 word codeptr, isdata[], addrxlate, bytecode, i, case, dest byte opcode, j, A_IS_TOS, X_IS_IFP - //puts("JIT compiler invoked for :$"); puth(defptr=>bytecodeaddr); putln + defptr=>interpaddr = indirectentry // assume compile will fail addrxlate = heapmark // heapalloc(512 + defptr->bytecodesize) - //if not addrxlate if isult(heapavail, 512 + defptr->bytecodesize) // 256 * sizeof(word) address xlate // // Not enough heap available // //puts("Not enough free heap\n") - defptr=>interpaddr = indirectentry return fin // @@ -26,7 +24,8 @@ def compiler(defptr)#0 // bytecode = addrxlate + 512 // def bytecode defcpy(bytecode, defptr) - //puts("Addr Xlate: $"); puth(addrxlate); putln + //puts("JITC:$"); puth(defptr=>bytecodeaddr); puts("=>$"); puth(bytecode) + //puts(",$"); puth(defptr->bytecodesize); putln // // Find all branch targets and optimization fences. Tag the opcode with the LSB set // @@ -159,7 +158,6 @@ def compiler(defptr)#0 codeptr->3 = $C0 // NATV CODE codeptr = codeptr + 4 i = 0 - fin while isule(codeptr, codemax) //putc('$'); puth(codeptr); putc(':') @@ -1309,24 +1307,15 @@ def compiler(defptr)#0 defptr->interpjsr = $4C // JMP defptr=>interpaddr = *jitcodeptr *jitcodeptr = codeptr - // - // Free working bufffers - // - //heaprelease(addrxlate) - //puts("Done compiling: $"); puth(defptr=>interpaddr); putln + //puts("Done compiling: $"); puth(defptr=>interpaddr) + //puts("->$"); puth(*jitcodeptr); putln //getc return fin loop // - // If we got here. we ran out of code buffer space. Overwrite interpreter - // entrypoint with standard bytecode interpreter + // If we got here we ran out of code buffer space. // - defptr=>interpaddr = indirectentry - // - // Free working bufffers - // - //heaprelease(addrxlate) //puts("Ran out of code buffer\n") //getc end diff --git a/src/libsrc/jitcore.pla b/src/libsrc/jitcore.pla index be2bcea..29f301d 100644 --- a/src/libsrc/jitcore.pla +++ b/src/libsrc/jitcore.pla @@ -28,15 +28,13 @@ def compiler(defptr)#0 word codeptr, isdata[], addrxlate, bytecode, i, case, dest, VX, VY byte opcode, j, A_IS_TOSL - //puts("JIT compiler invoked for :$"); puth(defptr=>bytecodeaddr); putln + defptr=>interpaddr = indirectentry // assume compile will fail addrxlate = heapmark // heapalloc(512 + defptr->bytecodesize) - //if not addrxlate if isult(heapavail, 512 + defptr->bytecodesize) // 256 * sizeof(word) address xlate // // Not enough heap available // //puts("Not enough free heap\n") - defptr=>interpaddr = indirectentry return fin // @@ -44,7 +42,8 @@ def compiler(defptr)#0 // bytecode = addrxlate + 512 // def bytecode defcpy(bytecode, defptr) - //puts("Addr Xlate: $"); puth(addrxlate); putln + //puts("JITC:$"); puth(defptr=>bytecodeaddr); puts("=>$"); puth(bytecode) + //puts(",$"); puth(defptr->bytecodesize); putln // // Find all branch targets and optimization fences. Tag the opcode with the LSB set // @@ -1535,24 +1534,15 @@ def compiler(defptr)#0 defptr->interpjsr = $4C // JMP defptr=>interpaddr = *jitcodeptr *jitcodeptr = codeptr - // - // Free working bufffers - // - //heaprelease(addrxlate) - //puts("Done compiling: $"); puth(defptr=>interpaddr); putln + //puts("Done compiling: $"); puth(defptr=>interpaddr) + //puts("->$"); puth(*jitcodeptr); putln //getc return fin loop // - // If we got here. we ran out of code buffer space. Overwrite interpreter - // entrypoint with standard bytecode interpreter + // If we got here we ran out of code buffer space. // - defptr=>interpaddr = indirectentry - // - // Free working bufffers - // - //heaprelease(addrxlate) //puts("Ran out of code buffer\n") //getc end diff --git a/src/libsrc/lines.pla b/src/libsrc/lines.pla new file mode 100644 index 0000000..39750b7 --- /dev/null +++ b/src/libsrc/lines.pla @@ -0,0 +1,506 @@ +include "inc/cmdsys.plh" +predef nopLin(a, b, c)#0 +predef nopPix(a, b)#0 + +byte jmpplot = $4C // Sneaky! +var plot = @nopPix +var hspan = @nopLin +var vspan = @nopLin +var err, shorterr, shortlen, longerr, longlen + +//def nopLin(a, b, c)#0 +//end +//def majorspans(majorstart, major, majorend, minor, dir, majorspan)#0 +// // +// // Initial half-span step +// // +// err = err + shorterr +// repeat +// majorspan(majorstart, major, minor)#0 +// minor = minor + dir // Move to next span +// majorstart = major + 1 // Start of next span = end of previous + 1 +// if err >= 0 // Short span +// err = err + shorterr +// major = major + shortlen +// else // Long span +// err = err + longerr +// major = major + longlen +// fin +// until major >= majorend +// // +// // Final half-span step +// // +// majorspan(majorstart, majorend, minor)#0 +//end +asm majorspans(majorstart, major, majorend, minor, dir, majorspan)#0 +!SOURCE "vmsrc/plvmzp.inc" + LDA $1000 ; ERRL + CLC + ADC $2000 ; SHORTERRL + STA $1000 ; ERRL + LDA $1001 ; ERRH + ADC $2001 ; SHORTERRH + STA $1001 ; ERRH + LDA ESTKL+0,X ; MAJORSPANL + STA $A000 + STA $B000 + LDA ESTKH+0,X ; MAJORSPANH + STA $A001 + STA $B001 +end +asm _majorspansA +- DEX + DEX + DEX + LDA ESTKL+8,X ; MAJORSTARTL + STA ESTKL+2,X + LDA ESTKH+8,X ; MAJORSTARTH + STA ESTKH+2,X + LDA ESTKL+7,X ; MAJORL + STA ESTKL+1,X + LDA ESTKH+7,X ; MAJORH + STA ESTKH+1,X + LDA ESTKL+5,X ; MINORL + STA ESTKL+0,X + LDA ESTKH+5,X ; MINORH + STA ESTKH+0,X + JSR $A000 + + LDA ESTKL+2,X ; MINORL + CLC + ADC ESTKL+1,X ; DIRL + STA ESTKL+2,X + LDA ESTKH+2,X ; MINORH + ADC ESTKH+1,X ; DIRH + STA ESTKH+2,X + + LDA ESTKL+4,X ; MAJORL + CLC + ADC #$01 + STA ESTKL+5,X ; MAJORSTARTL + LDA ESTKH+4,X ; MAJORH + ADC #$00 + STA ESTKH+5,X ; MAJORSTARTH +end +asm _majorspansB + LDY $1001 ; ERRH + BMI + +end +asm _majorspansC + LDA $1000 ; ERRL + CLC + ADC $2000 ; SHORTERRL + STA $1000 ; ERRL + TYA ; ERRH + ADC $2001 ; SHORTERRH + STA $1001 ; ERRH + LDA ESTKL+4,X ; MAJORL + CLC + ADC $3000 ; SHORTLENL + STA ESTKL+4,X + LDA ESTKH+4,X ; MAJORH + ADC $3001 ; SHORTLENH + STA ESTKH+4,X + LDA ESTKL+4,X ; MAJORL + CMP ESTKL+3,X ; MAJORENDL + LDA ESTKH+4,X ; MAJORH + SBC ESTKH+3,X ; MAJORENDH + BCC - + BCS ++ +end +asm _majorspansD ++ LDA $1000 ; ERRL + CLC + ADC $4000 ; LONGERRL + STA $1000 ; ERRL + TYA ; ERRH + ADC $4001 ; LONGERRL + STA $1001 ; ERRH + LDA ESTKL+4,X ; MAJORL + CLC + ADC $5000 ; LONGLENL + STA ESTKL+4,X + LDA ESTKH+4,X ; MAJORH + ADC $5001 ; LONGLENH + STA ESTKH+4,X + LDA ESTKL+4,X ; MAJORL + CMP ESTKL+3,X ; MAJORENDL + LDA ESTKH+4,X ; MAJORH + SBC ESTKH+3,X ; MAJORENDH + BCS ++ +end +asm _majorspansE + JMP $6000 +++ DEX + DEX + DEX + LDA ESTKL+8,X ; MAJORSTARTL + STA ESTKL+2,X + LDA ESTKH+8,X ; MAJORSTARTH + STA ESTKH+2,X + LDA ESTKL+6,X ; MAJORENDL + STA ESTKL+1,X + LDA ESTKH+6,X ; MAJORENDH + STA ESTKH+1,X + LDA ESTKL+5,X ; MINORL + STA ESTKL+0,X + LDA ESTKH+5,X ; MINORH + STA ESTKH+0,X + JSR $B000 + TXA + CLC + ADC #$06 + TAX + RTS +end +asm nopLin(a, b, c)#0 + INX +end +asm nopPix(a, b)#0 + INX + INX + RTS +end +//def hline(x1, x2, dx2, y, dy2, sy)#0 +// var dyx2, x +// +// err = dy2 - dx2 / 2 +// dyx2 = dy2 - dx2 +// for x = x1 to x2 +// plot(x, y)#0 +// if err >= 0 +// y = y + sy +// err = err + dyx2 +// else +// err = err + dy2 +// fin +// next +//end +asm hline(x1, x2, dx2, y, dy2, sy)#0 + LDA ESTKH+3,X ; DX2H + LSR + STA TMPH + LDA ESTKL+3,X ; DX2L + ROR + STA TMPL + LDA ESTKL+1,X ; DY2L + SEC + SBC TMPL + STA $1000 ; ERRL + LDA ESTKH+1,X ; DY2H + SBC TMPH + STA $1001 ; ERRH + LDA ESTKL+1,X ; DY2L + SEC + SBC ESTKL+3,X ; DX2L + STA ESTKL+3,X ; DYX2L + LDA ESTKH+1,X ; DY2H + SBC ESTKH+3,X ; DX2H + STA ESTKH+3,X ; DYX2H +- DEX + DEX + LDA ESTKL+7,X ; XL + STA ESTKL+1,X + LDA ESTKH+7,X ; XH + STA ESTKH+1,X + LDA ESTKL+4,X ; YL + STA ESTKL+0,X + LDA ESTKH+4,X ; YH + STA ESTKH+0,X +end +asm _hlineA + JSR $2000 ; PLOT + LDA $1001 ; ERRH + BMI + + LDA ESTKL+2,X ; YL + CLC + ADC ESTKL+0,X ; SYL + STA ESTKL+2,X + LDA ESTKH+2,X ; YH + ADC ESTKH+0,X ; SYH + STA ESTKH+2,X + LDA ESTKL+3,X ; DYX2L + LDY ESTKH+3,X ; DYX2H + BEQ ++ + BNE ++ +end +asm _hlineB ++ LDA ESTKL+1,X ; DY2L + LDY ESTKH+1,X ; DY2H +++ CLC + ADC $1000 ; ERRL + STA $1000 ; ERRL + TYA + ADC $1001 ; ERRH + STA $1001 ; ERRH + LDA ESTKL+5,X ; X1L + CMP ESTKL+4,X ; X2L + LDA ESTKH+5,X + SBC ESTKH+4,X + BCS + + INC ESTKL+5,X ; XL + BNE - + INC ESTKH+5,X ; XH + BCC - ++ TXA + ADC #$05 + TAX + RTS +end +//def vline(y1, y2, dy2, x, dx2, sx)#0 +// var dxy2, y +// +// err = dx2 - dy2 / 2 +// dxy2 = dx2 - dy2 +// for y = y1 to y2 +// plot(x, y)#0 +// if err >= 0 +// x = x + sx +// err = err + dxy2 +// else +// err = err + dx2 +// fin +// next +//end +asm vline(y1, y2, dy2, x, dx2, sx)#0 + LDA ESTKH+3,X ; DY2H + LSR + STA TMPH + LDA ESTKL+3,X ; DY2L + ROR + STA TMPL + LDA ESTKL+1,X ; DX2L + SEC + SBC TMPL + STA $1000 ; ERRL + LDA ESTKH+1,X ; DX2H + SBC TMPH + STA $1001 ; ERRH + LDA ESTKL+1,X ; DX2L + SEC + SBC ESTKL+3,X ; DX2L + STA ESTKL+3,X ; DXY2L + LDA ESTKH+1,X ; DX2H + SBC ESTKH+3,X ; DY2H + STA ESTKH+3,X ; DXY2H +- DEX + DEX + LDA ESTKL+4,X ; XL + STA ESTKL+1,X + LDA ESTKH+4,X ; XH + STA ESTKH+1,X + LDA ESTKL+7,X ; YL + STA ESTKL+0,X + LDA ESTKH+7,X ; YH + STA ESTKH+0,X +end +asm _vlineA + JSR $2000 ; PLOT + LDA $1001 ; ERRH + BMI + + LDA ESTKL+2,X ; XL + CLC + ADC ESTKL+0,X ; SXL + STA ESTKL+2,X + LDA ESTKH+2,X ; XH + ADC ESTKH+0,X ; SXH + STA ESTKH+2,X + LDA ESTKL+3,X ; DXY2L + LDY ESTKH+3,X ; DXY2H + BEQ ++ + BNE ++ +end +asm _vlineB ++ LDA ESTKL+1,X ; DX2L + LDY ESTKH+1,X ; DX2H +++ CLC + ADC $1000 ; ERRL + STA $1000 ; ERRL + TYA + ADC $1001 ; ERRH + STA $1001 ; ERRH + LDA ESTKL+5,X ; Y1L + CMP ESTKL+4,X ; Y2L + LDA ESTKH+5,X + SBC ESTKH+4,X + BCS + + INC ESTKL+5,X ; YL + BNE - + INC ESTKH+5,X ; YH + BCC - ++ TXA + ADC #$05 + TAX + RTS +end + +export def setlinespans(h, v)#0 + hspan = h + vspan = v +end +def hmajorspans(x1, y1, x2, y2, dx, dy, sy)#0 + var dy2, halflen, rem + // + // Half-span length and error + // + dy2 = dy * 2 + halflen, rem = divmod(dx, dy2) + err = dy2 - rem + // + // Long-span length = half-span length * 2 + // + longlen = (halflen + 1) * 2 + longerr = err * 2 + if longerr >= dy2 + longerr = longerr - dy2 + longlen-- + fin + // + // Short-span length = long-span length - 1 + // + shortlen = longlen - 1 + shorterr = longerr - dy2 + majorspans(x1, x1 + halflen, x2, y1, sy, hspan) +end +def vmajorspans(x1, y1, x2, y2, dx, dy, sx)#0 + var dx2, halflen, rem + + // + // Half-span length and error + // + dx2 = dx * 2 + halflen, rem = divmod(dy, dx2) + err = dx2 - rem + // + // Long-span length = half-span length * 2 + // + longlen = (halflen + 1) * 2 + longerr = err * 2 + if longerr >= dx2 + longerr = longerr - dx2 + longlen-- + fin + shortlen = longlen - 1 + shorterr = longerr - dx2 + majorspans(y1, y1 + halflen, y2, x1, sx, vspan) +end +export def linespans(x1, y1, x2, y2)#0 + var dx, dy, dx2, dy2, halflen, rem, sx, sy + + sx = 1 + sy = 1 + dx = x2 - x1 + if dx < 0 + sx = -1; dx = -dx + fin + dy = y2 - y1 + if dy < 0 + sy = -1; dy = -dy + fin + if dx >= dy + if sx < 0 + y1, y2 = y2, y1 + x1, x2 = x2, x1 + sy = -sy + fin + if dy == 0 + hspan(x1, x2, y1)#0; return + fin + // + // JIT optimize setup + // + hmajorspans(x1, y1, x2, y2, dx, dy, sy) + else + if sy < 0 + x1, x2 = x2, x1 + y1, y2 = y2, y1 + sx = -sx + fin + if dx == 0 + vspan(y1, y2, x1)#0; return + fin + // + // JIT optimize inner setup + // + vmajorspans(x1, y1, x2, y2, dx, dy, sx) + fin +end +export def setlineplot(p)#0 + plot = p +end +export def line(x1, y1, x2, y2)#0 + var sx, sy, dx2, dy2 + + sx = 1 + sy = 1 + dx2 = (x2 - x1) * 2 + if dx2 < 0 + sx = -1; dx2 = -dx2 + fin + dy2 = (y2 - y1) * 2 + if dy2 < 0 + sy = -1; dy2 = -dy2 + fin + if dx2 >= dy2 + if sx < 0 + x1, x2 = x2, x1 + y1, y2 = y2, y1 + sy = -sy + fin + hline(x1, x2, dx2, y1, dy2, sy) + else + if sy < 0 + y1, y2 = y2, y1 + x1, x2 = x2, x1 + sx = -sx + fin + vline(y1, y2, dy2, x1, dx2, sx) + fin + end + +// +// Assembly fixups +// +majorspans:1 = @err +majorspans:5 = @shorterr +majorspans:8 = @err +majorspans:11 = @err.1 +majorspans:14 = @shorterr.1 +majorspans:17 = @err.1 +majorspans:22 = @_majorspansA.28 +majorspans:25 = @_majorspansE.31 +majorspans:30 = @_majorspansA.29 +majorspans:33 = @_majorspansE.32 +_majorspansB:1 = @err.1 +_majorspansC:1 = @err +_majorspansC:5 = @shorterr +_majorspansC:8 = @err +_majorspansC:12 = @shorterr.1 +_majorspansC:15 = @err.1 +_majorspansC:21 = @shortlen +_majorspansC:28 = @shortlen.1 +_majorspansD:1 = @err +_majorspansD:5 = @longerr +_majorspansD:8 = @err +_majorspansD:12 = @longerr.1 +_majorspansD:15 = @err.1 +_majorspansD:21 = @longlen +_majorspansD:28 = @longlen.1 +_majorspansE:1 = @_majorspansA +hline:16 = @err +hline:23 = @err.1 +_hlineA:1 = @jmpplot +_hlineA:4 = @err.1 +_hlineB:6 = @err +_hlineB:9 = @err +_hlineB:13 = @err.1 +_hlineB:16 = @err.1 +vline:16 = @err +vline:23 = @err.1 +_vlineA:1 = @jmpplot +_vlineA:4 = @err.1 +_vlineB:6 = @err +_vlineB:9 = @err +_vlineB:13 = @err.1 +_vlineB:16 = @err.1 +done diff --git a/src/libsrc/wiznet.pla b/src/libsrc/wiznet.pla deleted file mode 100644 index 079ebf5..0000000 --- a/src/libsrc/wiznet.pla +++ /dev/null @@ -1,993 +0,0 @@ -// -// Wiznet 5100 based ethernet card -// -// TCP/IP is built into hardware, so no dependencies on the software -// layers, like the Uthernet -// -include "inc/cmdsys.plh" -// -// Net object -// -import inet - word iNet -end -struc t_inet - word initIP - word serviceIP - word openUDP - word sendUDP - word closeUDP - word listenTCP - word connectTCP - word sendTCP - word closeTCP - word setInterfaceIP - word getInterfaceHA - word setCallback - word setParam -end -// -// Module don't free memory -// -const modkeep = $2000 -const modinitkeep = $4000 -// -// Wiznet registers -// -const WIZ_MR = $00 -const WIZ_GWR = $01 -const WIZ_SUBR = $05 -const WIZ_SHAR = $09 -const WIZ_SIPR = $0F -const WIZ_IR = $15 -const WIZ_IMR = $16 -const WIZ_RTR = $17 -const WIZ_RCR = $19 -const WIZ_RMSR = $1A -const WIZ_TMSR = $1B -const WIZ_PATR = $1C -const WIZ_PTMR = $28 -const WIZ_PMGC = $29 -const WIZ_UIPR = $2A -const WIZ_UPRT = $2E -// -// Wiznet socket registers -// -const WIZ_SREGS = $0400 -const WIZ_SSIZE = $0100 -const WIZ_SOCK0 = $0400 -const WIZ_SOCK1 = $0500 -const WIZ_SOCK2 = $0600 -const WIZ_SOCK3 = $0700 -const WIZ_SnMR = $00 -const WIZ_SnCR = $01 -const WIZ_SnIR = $02 -const WIZ_SnSR = $03 -const WIZ_SnPORT = $04 -const WIZ_SnDHAR = $06 -const WIZ_SnDIPR = $0C -const WIZ_SnDPORT = $10 -const WIZ_SnMSSR = $12 -const WIZ_SnPROTO = $14 -const WIZ_SnTOS = $15 -const WIZ_SnTTL = $16 -const WIZ_SnFSR = $20 -const WIZ_SnTXRD = $22 -const WIZ_SnTXWR = $24 -const WIZ_SnRSR = $26 -const WIZ_SnRXRD = $28 -// -// Wiznet socket data -// -const WIZ_TXMEM = $4000 -const WIZ_TXSIZE = $0800 -const WIZ_TXMASK = WIZ_TXSIZE-1 -const WIZ_TXMEM0 = $4000 -const WIZ_TXMEM1 = $4800 -const WIZ_TXMEM2 = $5000 -const WIZ_TXMEM3 = $5800 -const WIZ_RXMEM = $6000 -const WIZ_RXSIZE = $0800 -const WIZ_RXMASK = WIZ_RXSIZE-1 -const WIZ_RXMEM0 = $6000 -const WIZ_RXMEM1 = $6800 -const WIZ_RXMEM2 = $7000 -const WIZ_RXMEM3 = $7800 -// -// Wiznet indirect registers -// -byte regidx, regdata -word slot, saveidx -// -// Wiznet MAC address -// -byte[6] wizMAC = $00,$0A,$99,$1E,$02,$B0 -// -// Wiznet IP addresses -// -byte[4] localip -byte[4] subnet -byte[4] gateway -// -// Predefine service routine -// -predef wizServiceIP -// -// Segment list element -// -struc t_segment - word seg_buf - word seg_len -end -// -// Max Ethernet frame size -// -const MAX_FRAME_SIZE = 1518 -const MAC_BROADCAST = $FFFF -const MAC_SIZE = 6 -// -// Ethernet header -// -struc t_ethrhdr - byte[MAC_SIZE] ethr_dst - byte[MAC_SIZE] ethr_src - word ethr_payload -end -const PAYLOAD_IP = $0008 // BE format -const PAYLOAD_ARP = $0608 // BE format -// -// IP datagram header -// -const IP4ADR_SIZE = 4 -struc t_iphdr - byte ip_vers_hlen - byte ip_service - word ip_length - word ip_id - word ip_flags_fragofst - byte ip_ttl - byte ip_proto - word ip_chksm - byte[IP4ADR_SIZE] ip_src - byte[IP4ADR_SIZE] ip_dst - byte[] ip_options -end -const IP_BROADCAST = $FFFF -const IP_PROTO_ICMP = $01 -const IP_PROTO_UDP = $11 -const IP_PROTO_TCP = $06 -word bcast = IP_BROADCAST, IP_BROADCAST -// -// ICMP type/codes -// -const IP_PROTO_ICMP = 1 -const ICMP_ECHO_REQST = 8 -const ICMP_ECHO_REPLY = 0 -// -// ICMP message format -// -struc t_icmp - byte icmp_type - byte icmp_code - word icmp_chksm - word[2] icmp_header -end -// -// UDP IPv4 psuedo header -// -struc t_piphdr - byte[IP4ADR_SIZE] pip_src - byte[IP4ADR_SIZE] pip_dst - byte pip_zero - byte pip_proto - word pip_len -end -// -// UDP header -// -struc t_udphdr - word udp_src - word udp_dst - word udp_len - word udp_chksm -end -// -// TCP header -// -struc t_tcphdr - word tcp_src - word tcp_dst - word tcp_len - word tcp_chksm -end -// -// Local network parameters -// -const MAX_WIZ_CHANNELS = 4 -// -// Channel protocols -// -const WIZ_PROTO_CLOSED = 0 -const WIZ_PROTO_TCP = 1 -const WIZ_PROTO_UDP = 2 -const WIZ_PROTO_IP = 3 -const WIZ_PROTO_RAW = 4 -// -// State transistions -// -const TCP_STATE_CLOSED = 0 -const TCP_STATE_CLOSING = 1 -const TCP_STATE_LISTEN = 2 -const TCP_STATE_CONNECT = 3 -const TCP_STATE_OPEN = 4 -// -// HW channels -// -struc t_channel - byte channel_proto - byte channel_state - word channel_regs - word channel_txmem - word channel_rxmem - word channel_lclport - word channel_remport - byte[4] channel_remip - word channel_recv_func - word channel_recv_parm -end -byte[t_channel * MAX_WIZ_CHANNELS] wizChannel -// -// Service ICMP hook -// -export word hookICMP -// -// Defines for ASM routines -// -asm equates - !SOURCE "vmsrc/plvmzp.inc" -end -// -// Swap bytes in word -// -asm swab - LDA ESTKL,X - LDY ESTKH,X - STA ESTKH,X - STY ESTKL,X - RTS -end -// -// Wiznet I/O functions -// -// POKE WORD TO I/O SPACE -// Note: Big Endian format -// -asm _pokeiow - LDA ESTKH,X -end -asm _pokeiowl - STA $C000 - LDA ESTKL,X -end -asm _pokeiowh - STA $C000 - RTS -end -// -// POKE BYTE TO I/O SPACE -// -asm _pokeio - LDA ESTKL,X -end -asm _pokeiol - STA $C000 - RTS -end -// -// PEEK BYTE FROM I/O SPACE -// -asm _peekio - DEX -end -asm _peekiol - LDA $C000 - STA ESTKL,X - LDA #$00 - STA ESTKH,X - RTS -end -// -// PEEK WORD FROM I/O SPACE -// Note: Big Endian format -// -asm _peekiow - DEX -end -asm _peekiowl - LDA $C000 - STA ESTKH,X -end -asm _peekiowh - LDA $C000 - STA ESTKL,X - RTS -end -// -// WRITE DATA INTO I/O SPACE -// pokedata(BUF, LEN) -// -asm pokedata - LDA ESTKL+1,X - STA SRCL - LDA ESTKH+1,X - STA SRCH - LDY ESTKL,X - BEQ POKELP - LDY #$00 - INC ESTKH,X -POKELP LDA (SRC),Y -end -asm _pokedata - STA $C000 - INY - BNE + - INC SRCH -+ DEC ESTKL,X - BNE POKELP - DEC ESTKH,X - BNE POKELP - INX - RTS -end -// -// READ DATA FROM I/O SPACE -// peekdata(BUF, LEN) -// -asm peekdata - LDA ESTKL+1,X - STA DSTL - LDA ESTKH+1,X - STA DSTH - LDY ESTKL,X - BEQ PEEKLP - LDY #$00 - INC ESTKH,X -end -asm _peekdata -PEEKLP LDA $C000 - STA (DST),Y - INY - BNE + - INC DSTH -+ DEC ESTKL,X - BNE PEEKLP - DEC ESTKH,X - BNE PEEKLP - INX - RTS -end -def pokeiow(io, data) - _pokeiowl.1 = io - _pokeiowh.1 = io+1 - return _pokeiow(data) -end -def pokeio(io, data) - _pokeiol.1 = io - return _pokeio(data) -end -def peekio(io) - _peekiol.1 = io - return _peekio() -end -def peekiow(io) - _peekiowl.1 = io - _peekiowh.1 = io+1 - return _peekiow() -end -def pokereg(reg, data) - _pokeiow(reg) - return _pokeio(data) -end -def peekreg(reg) - _pokeiow(reg) - return _peekio() -end -def pokeregs(reg, buf, len) -// _pokeiow(reg) -// return pokedata(buf, len) - word i - len = len - 1 - for i = 0 to len - _pokeiow(reg + i) - _pokeio(buf->[i]) - next -end -def peekregs(reg, buf, len) -// _pokeiow(reg) -// return peekdata(buf, len) -// There is an issue missing data on back-to-back reads - word i - len = len - 1 - for i = 0 to len - _pokeiow(reg + i) - buf->[i] = _peekio() - next -end -def pokeregw(reg, dataw) - _pokeiow(reg) - _pokeio(dataw.1) - return _pokeio(dataw.0) -end -def peekregw(reg) - word dataw - - _pokeiow(reg) - dataw.1 = _peekio() - _pokeiow(reg + 1) - dataw.0 = _peekio() - return dataw -end -// -// DEBUG -// -def putb(hexb) - return call($FDDA, hexb, 0, 0, 0) -end -def puth(hex) - return call($F941, hex >> 8, hex, 0, 0) -end -def putip(ipptr) - byte i - - for i = 0 to 2 - puti(ipptr->[i]); putc('.') - next - return puti(ipptr->[i]) -end -// -// Send UDP datagram -// -def wizSendUDP(wiz, ipdst, portdst, data, len) - word wizregs, wizdata, txrr, txwr, splitlen - - wizregs = wiz=>channel_regs - wizdata = wiz=>channel_txmem - if !ipdst - ipdst = @bcast - fin - // - // Wait for Tx room - // - repeat; until peekregw(wizregs + WIZ_SnFSR) >= len - // - // Calc new write ptr, check for split - // - txwr = peekregw(wizregs + WIZ_SnTXWR) - txrr = txwr & WIZ_TXMASK - if txrr + len > WIZ_TXSIZE - splitlen = WIZ_TXSIZE - txrr - pokeregs(wizdata + txrr, data, splitlen) - pokeregs(wizdata, data + splitlen, len - splitlen) - else - pokeregs(wizdata + txrr, data, len) - fin - // - // Set destination address/port - // - pokeregs(wizregs + WIZ_SnDIPR, ipdst, IP4ADR_SIZE) - pokeregw(wizregs + WIZ_SnDPORT, portdst) - // - // Update write pointer and send - // - pokeregw(wizregs + WIZ_SnTXWR, txwr + len) - pokereg(wizregs + WIZ_SnCR, $20) // SEND -end -// -// Open UDP channel and set datagram received callback -// -def wizOpenUDP(localport, callback, param) - word wiz - byte i - - if !localport; return -1; fin // invalid port - // - // Look for an existing notification on localport - // - //putc('O') - wiz = @wizChannel - for i = 1 to MAX_WIZ_CHANNELS - if wiz->channel_proto == IP_PROTO_UDP and wiz=>channel_lclport == localport - break - fin - wiz = wiz + t_channel - next - if i > MAX_WIZ_CHANNELS - // - // Add notification on localport if room - // - wiz = @wizChannel - for i = 1 to MAX_WIZ_CHANNELS - if !wiz->channel_proto - break - fin - wiz = wiz + t_channel - next - if i > MAX_WIZ_CHANNELS - return 0 - fin - fin - //putc('0' + i);putln - // - // Fill in this channel and open it - // - wiz->channel_proto = WIZ_PROTO_UDP - wiz=>channel_lclport = localport - wiz=>channel_recv_func = callback - wiz=>channel_recv_parm = param - pokeregw(wiz=>channel_regs + WIZ_SnPORT, localport) - pokereg(wiz=>channel_regs + WIZ_SnMR, $02) // UDP protocol - pokereg(wiz=>channel_regs + WIZ_SnCR, $01) // OPEN - return wiz -end -// -// Close UDP port -// -def wizCloseUDP(wiz) - //putc('S') - if isuge(wiz, @wizChannel) and isult(wiz, @wizChannel + MAX_WIZ_CHANNELS * t_channel) - // - // Clear notiications on this port - // - if wiz->channel_proto == WIZ_PROTO_UDP - //putc('1' + ((wiz=>channel_regs - WIZ_SREGS) >> 8));putln - wiz->channel_proto = WIZ_PROTO_CLOSED - pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE - return 0 - fin - fin - //putc('!');putln - // - // Invalid port - // - return -1 -end -// -// Open TCP socket in SERVER mode -// -def wizListenTCP(lclport, callback, param) - word wiz - byte i - - // - // Look for an existing notification on localport - // - //putc('L') - wiz = @wizChannel - for i = 1 to MAX_WIZ_CHANNELS - if wiz->channel_proto == WIZ_PROTO_TCP and wiz->channel_state == TCP_STATE_LISTEN and wiz=>channel_lclport == lclport - break - fin - wiz = wiz + t_channel - next - if i > MAX_WIZ_CHANNELS - // - // Add notification on localport if room - // - wiz = @wizChannel - for i = 1 to MAX_WIZ_CHANNELS - if !wiz->channel_proto - break - fin - wiz = wiz + t_channel - next - if i > MAX_WIZ_CHANNELS - return 0 - fin - fin - //putc('0' + i);putln - // - // Fill in this channel and open it - // - wiz->channel_proto = WIZ_PROTO_TCP - wiz->channel_state = TCP_STATE_LISTEN - wiz=>channel_remip:0 = 0 - wiz=>channel_remip:2 = 0 - wiz=>channel_remport = 0 - wiz=>channel_lclport = lclport - wiz=>channel_recv_func = callback - wiz=>channel_recv_parm = param - pokereg(wiz=>channel_regs + WIZ_SnMR, $01) // TCP protocol - pokeregw(wiz=>channel_regs + WIZ_SnPORT, lclport) - pokereg(wiz=>channel_regs + WIZ_SnCR, $01) // OPEN - while peekreg(wiz=>channel_regs + WIZ_SnSR) <> $13; loop // Wait for init - pokereg(wiz=>channel_regs + WIZ_SnCR, $02) // LISTEN - return wiz -end -// -// Open TCP socket in CLIENT mode -// -def wizConnectTCP(remip, remport, lclport, callback, param) - word wiz - byte i - - // - // Look for an existing notification on localport - // - wiz = @wizChannel - for i = 1 to MAX_WIZ_CHANNELS - if wiz->channel_proto == WIZ_PROTO_TCP and wiz->channel_state == TCP_STATE_CONNECT and wiz=>channel_lclport == lclport - break - fin - wiz = wiz + t_channel - next - if i > MAX_WIZ_CHANNELS - // - // Add notification on localport if room - // - wiz = @wizChannel - for i = 1 to MAX_WIZ_CHANNELS - if !wiz->channel_proto - break - fin - wiz = wiz + t_channel - next - if i > MAX_WIZ_CHANNELS - return 0 - fin - fin - // - // Fill in this channel and open it - // - wiz->channel_proto = WIZ_PROTO_TCP - wiz->channel_state = TCP_STATE_CONNECT - wiz=>channel_remip:0 = remip=>0 - wiz=>channel_remip:2 = remip=>2 - wiz=>channel_remport = remport - wiz=>channel_lclport = lclport - wiz=>channel_recv_func = callback - wiz=>channel_recv_parm = param - pokereg(wiz=>channel_regs + WIZ_SnMR, $01) // TCP protocol - pokeregs(wiz=>channel_regs + WIZ_SnDIPR, remip, IP4ADR_SIZE) - pokeregw(wiz=>channel_regs + WIZ_SnDPORT, remport) - pokeregw(wiz=>channel_regs + WIZ_SnPORT, lclport) - pokereg(wiz=>channel_regs + WIZ_SnCR, $01) // OPEN - while peekreg(wiz=>channel_regs + WIZ_SnSR) <> $13; loop // Wait for init - pokereg(wiz=>channel_regs + WIZ_SnCR, $04) // CONNECT - return wiz -end -// -// Write to TCP socket -// -def wizSendTCP(wiz, data, len) - word wizregs, wizdata, txrr, txwr, splitlen - - if wiz->channel_state <> TCP_STATE_OPEN; return -1; fin - //putc('W');puti(len);putc(':') - wizregs = wiz=>channel_regs - wizdata = wiz=>channel_txmem - // - // Wait for Tx room - // - repeat; until peekregw(wizregs + WIZ_SnFSR) >= len - // - // Calc new write ptr, check for split - // - txwr = peekregw(wizregs + WIZ_SnTXWR) - txrr = txwr & WIZ_TXMASK - if txrr + len > WIZ_TXSIZE - splitlen = WIZ_TXSIZE - txrr - pokeregs(wizdata + txrr, data, splitlen) - pokeregs(wizdata, data + splitlen, len - splitlen) - //putc('(');puti(splitlen);putc(',');puti(len-splitlen);putc(')') - else - pokeregs(wizdata + txrr, data, len) - fin - //puth(txrr);putc('-');putc('>');puth(txwr+len);putln - // - // Update write pointer and send - // - pokeregw(wizregs + WIZ_SnTXWR, txwr + len) - pokereg(wizregs + WIZ_SnCR, $20) // SEND -end -// -// Close TCP socket -// -def wizCloseTCP(wiz) - if isuge(wiz, @wizChannel) and isult(wiz, @wizChannel + MAX_WIZ_CHANNELS * t_channel) - // - // Clear notiications on this port - // - if wiz->channel_proto == WIZ_PROTO_TCP and (wiz->channel_state == TCP_STATE_OPEN or wiz->channel_state == TCP_STATE_CLOSING) - wiz->channel_state = TCP_STATE_CLOSING - pokereg(wiz=>channel_regs + WIZ_SnCR, $08) // DISCON - repeat - wizServiceIP() - until wiz->channel_state == TCP_STATE_CLOSED - wiz->channel_proto = WIZ_PROTO_CLOSED - return 0 - fin - fin - // - // Invalid port - // - return -1 -end -// -// Update notify callback -// -def wizSetCallback(wiz, callback) - if wiz->channel_proto == WIZ_PROTO_UDP or wiz->channel_proto == WIZ_PROTO_TCP - // - // Update callback on this port - // - wiz=>channel_recv_func = callback - return 0 - fin - // - // Invalid port - // - return -1 -end -// -// Update notify param -// -def wizSetParam(wiz, param) - if wiz->channel_proto == WIZ_PROTO_UDP or wiz->channel_proto == WIZ_PROTO_TCP - // - // Update param on this port - // - wiz=>channel_recv_parm = param - return 0 - fin - // - // Invalid port - // - return -1 -end -// -// Service incoming packets -// -def wizServiceIP - word wiz, wizregs, wizdata, rxlen, rxrr, rxwr, rxpkt, splitlen - byte ir, i, sir - - ir = peekreg(WIZ_IR) - if ir and ir <> $FF // Ignore spurious read of IR - //putc('I');putb(ir) - wiz = @wizChannel - for i = 0 to 3 - when ir & (1 << i) - is 1 - is 2 - is 4 - is 8 - wizregs = wiz=>channel_regs - wizdata = wiz=>channel_rxmem - sir = peekreg(wizregs + WIZ_SnIR) - when wiz->channel_proto - is WIZ_PROTO_TCP - if sir & $01 - //putc('C') - // - // Connect TCP socket - // - when wiz->channel_state - is TCP_STATE_LISTEN - peekregs(wiz=>channel_regs + WIZ_SnDIPR, @wiz=>channel_remip, IP4ADR_SIZE) - wiz=>channel_remport = peekregw(wiz=>channel_regs + WIZ_SnDPORT) - is TCP_STATE_CONNECT - wiz->channel_state = TCP_STATE_OPEN - break - otherwise - //putc('?') - wend - fin - if sir & $04 - //putc('R') - // - // Receive TCP packet - // - rxlen = peekregw(wizregs + WIZ_SnRSR) - rxrr = peekregw(wizregs + WIZ_SnRXRD) - rxwr = rxrr & WIZ_RXMASK - rxpkt = heapalloc(rxlen) - //puti(rxlen);putc(':') - if rxwr + rxlen > WIZ_RXSIZE - splitlen = WIZ_RXSIZE - rxwr - peekregs(wizdata + rxwr, rxpkt, splitlen) - peekregs(wizdata, rxpkt + splitlen, rxlen - splitlen) - //putc('(');puti(splitlen);putc(',');puti(rxlen-splitlen);putc(')') - else - peekregs(wizdata + rxwr, rxpkt, rxlen) - fin - //puth(rxwr);putc('-');putc('>');puth(rxwr+rxlen);putln - pokeregw(wizregs + WIZ_SnRXRD, rxrr + rxlen) - pokereg(wizregs + WIZ_SnCR, $40) // RECV - wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,wiz=>channel_lclport,rxpkt,rxlen,wiz=>channel_recv_parm) - heaprelease(rxpkt) - fin - if sir & $02 - //putc('S') - // - // Close TCP socket - // - when wiz->channel_state - is TCP_STATE_OPEN - wiz->channel_state = TCP_STATE_CLOSING - wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,0,wiz=>channel_lclport,0,wiz=>channel_recv_parm) - break - is TCP_STATE_CLOSING - wiz->channel_state = TCP_STATE_CLOSED - pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE - break - otherwise - //putc('?') - wend - fin - if sir & $08 - //putc('T') - // - // Timeout on TCP socket - // - when wiz->channel_state - is TCP_STATE_OPEN - wiz->channel_state = TCP_STATE_CLOSING - wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,wiz=>channel_lclport,0,0,wiz=>channel_recv_parm) - break - is TCP_STATE_CONNECT - wiz=>channel_recv_func(@wiz=>channel_remip,wiz=>channel_remport,wiz=>channel_lclport,0,0,wiz=>channel_recv_parm) - is TCP_STATE_CLOSING - wiz->channel_state = TCP_STATE_CLOSED - pokereg(wiz=>channel_regs + WIZ_SnCR, $10) // CLOSE - break - otherwise - //putc('?') - wend - fin - //if sir & $10 - //putc('W');putc('O');putc('K');puth(peekregw(wiz=>channel_regs+WIZ_SnTXWR));putln - // - // Write TCP socket OK - // - //fin - break - is WIZ_PROTO_UDP - //putc('U');putb(sir) - if sir & $04 - //putc('R') - // - // Receive UDP packet - // - rxlen = peekregw(wizregs + WIZ_SnRSR) - rxrr = peekregw(wizregs + WIZ_SnRXRD) - rxwr = rxrr & WIZ_RXMASK - rxpkt = heapalloc(rxlen) - if rxwr + rxlen >= WIZ_RXSIZE - //putc('!') - splitlen = WIZ_RXSIZE - rxwr - peekregs(wizdata + rxwr, rxpkt, splitlen) - peekregs(wizdata, rxpkt + splitlen, rxlen - splitlen) - else - peekregs(wizdata + rxwr, rxpkt, rxlen) - fin - //putc('=');putip(rxpkt);putc(' ');puti(rxlen) - //putc('/');puti(swab(rxpkt=>6)) - //putc(' ');puth(rxrr);putc(' ');puth(rxwr);putln - pokeregw(wizregs + WIZ_SnRXRD, rxrr + rxlen) - pokereg(wizregs + WIZ_SnCR, $40) // RECV - wiz=>channel_recv_func(rxpkt,swab(rxpkt=>4),rxpkt+8,rxlen-8,wiz=>channel_recv_parm) - heaprelease(rxpkt) - fin - break - otherwise - wend - pokereg(wiz=>channel_regs + WIZ_SnIR, sir) // Clear SnIR - ir = ir ^ (1 << i) - break - wend - wiz = wiz + t_channel - next - if ir - // - // Clear IR for now - // - pokereg(WIZ_IR, ir) - fin - fin -end -// -// Set the local IP addresses -// -def setWizIP(newIP, newSubnet, newGateway) - if newIP - localip:0 = newIP=>0; localip:2 = newIP=>2 - pokeregs(WIZ_SIPR, newIP, IP4ADR_SIZE) - fin - if newSubnet - subnet:0 = newSubnet=>0; subnet:2 = newSubnet=>2 - pokeregs(WIZ_SUBR, newSubnet, IP4ADR_SIZE) - fin - if newGateway - gateway:0 = newGateway=>0; gateway:2 = newGateway=>2 - pokeregs(WIZ_GWR, newGateway, IP4ADR_SIZE) - fin -end -// -// Get the interface hardware address -// -def getWizHA(ha) - if ha - ha=>0 = wizMAC:0; ha=>2 = wizMAC:2; ha=>4 = wizMAC:4 - fin - return MAC_SIZE -end -// -// Identify Wiznet card and initialize -// -for slot = $90 to $F0 step $10 - regdata = peekio(slot) - if (regdata & $E4) == $00 - pokeio(slot, $03) // Try setting auto-increment indirect I/F - if peekio(slot) == $03 - saveidx = peekiow(slot + 1) - peekio(slot + 3) // Dummy read to data register should increment index - if peekiow(slot + 1) == saveidx + 1 - // - // Good chance this is it - // - pokeio(slot, $80) // RESET - regidx = slot + 1 - regdata = slot + 3 - _pokedata.1 = regdata - _peekdata.1 = regdata - pokeio(slot, $03) // Auto-increment indirect I/F + enable ping - // - // The following looks redundant, but it sets up the peek/poke locations - // for peekreg(s)/pokereg(s) - // - pokeiow(regidx, WIZ_MR) - pokeio(regdata, $03) // Auto-increment indirect I/F + enable ping - peekio(regdata) - // - // Initialize common registers - // - pokeregs(WIZ_SHAR, @wizMAC, 6) // MAC addr - pokeregw(WIZ_RTR, 5000) // Timeout period to 500ms - pokereg(WIZ_RMSR, $55) // 2K Rx memory/channel - pokereg(WIZ_TMSR, $55) // 2K Tx memory/channel - // - // Fill channel structure - // - saveidx = @wizChannel - for slot = 0 to 3 - saveidx=>channel_regs = WIZ_SREGS + (WIZ_SSIZE * slot) - saveidx=>channel_txmem = WIZ_TXMEM + (WIZ_TXSIZE * slot) - saveidx=>channel_rxmem = WIZ_RXMEM + (WIZ_RXSIZE * slot) - saveidx = saveidx + t_channel - next - // - // Fill in Net class - // - iNet:serviceIP = @wizServiceIP - iNet:openUDP = @wizOpenUDP - iNet:sendUDP = @wizSendUDP - iNet:closeUDP = @wizCloseUDP - iNet:listenTCP = @wizListenTCP - iNet:connectTCP = @wizConnectTCP - iNet:sendTCP = @wizSendTCP - iNet:closeTCP = @wizCloseTCP - iNet:setInterfaceIP = @setWizIP - iNet:getInterfaceHA = @getWizHA - iNet:setCallback = @wizSetCallback - iNet:setParam = @wizSetParam - return modkeep - fin - fin - pokeio(slot, regdata) // Restore register - fin -next -// -// Not found -// -return -1 -done diff --git a/src/makefile b/src/makefile index bf3c631..31bf46a 100755 --- a/src/makefile +++ b/src/makefile @@ -7,20 +7,30 @@ PLVM02 = rel/apple/PLASMA.SYSTEM\#FF2000 PLVMJIT = rel/apple/PLVM.128\#FF2000 PLVM802 = rel/apple/PLVM16\#FF2000 PLVM03 = rel/apple/SOS.INTERP\#050000 +PLVMJIT03 = rel/apple/SOS.INTERPJIT\#050000 SOSCMD = rel/apple/SOS.CMD\#FE1000 +SOSCMDJIT = rel/apple/SOS.CMDJIT\#FE1000 CMD = rel/apple/CMD\#061000 CMDJIT = rel/apple/CMD128\#061000 PLVMZP_C64 = vmsrc/c64/plvmzp.inc PLVMC64 = rel/c64/PLASMA ED = rel/ED\#FE1000 +ZIP = rel/apple/ZIP\#FE1000 JIT = rel/apple/JIT\#FE1000 JIT16 = rel/apple/JIT16\#FE1000 JITUNE = rel/apple/JITUNE\#FE1000 SOS = rel/apple/SOS\#FE1000 -ROD = rel/ROD\#FE1000 +ROD = rel/apple/ROD\#FE1000 +COPY = rel/apple/COPY\#FE1000 +DEL = rel/apple/DEL\#FE1000 +REN = rel/apple/REN\#FE1000 +CAT = rel/apple/CAT\#FE1000 +NEWDIR = rel/apple/NEWDIR\#FE1000 +TYPE = rel/apple/TYPE\#FE1000 SIEVE = rel/SIEVE\#FE1000 PRIMEGAP = rel/PRIMEGAP\#FE1000 ARGS = rel/ARGS\#FE1000 +MATCHFILES = rel/apple/MATCHFILES\#FE1000 SPIPORT = rel/apple/SPIPORT\#FE1000 SDFAT = rel/apple/SDFAT\#FE1000 FATCAT = rel/apple/FATCAT\#FE1000 @@ -30,6 +40,8 @@ FATWDSK = rel/apple/FATWRITEDSK\#FE1000 FATRDSK = rel/apple/FATREADDSK\#FE1000 FILEIO_APL = rel/apple/FILEIO\#FE1000 CONIO_APL = rel/apple/CONIO\#FE1000 +INT32 = rel/INT32\#FE1000 +INT32TEST = rel/INT32TEST\#FE1000 SANE = rel/SANE\#FE1000 FPSTR = rel/FPSTR\#FE1000 FPU = rel/FPU\#FE1000 @@ -47,8 +59,16 @@ INET = rel/INET\#FE1000 DHCP = rel/DHCP\#FE1000 HTTPD = rel/HTTPD\#FE1000 TFTPD = rel/TFTPD\#FE1000 -DGR = rel/apple/DGR\#FE1000 +HGRLIB = rel/apple/HGRLIB\#FE1000 +GRLIB = rel/apple/GRLIB\#FE1000 +DGRLIB = rel/apple/DGRLIB\#FE1000 +HGRSPRITE = rel/apple/HGRSPRITE\#FE1000 +HGRTILE = rel/apple/HGRTILE\#FE1000 +HGRFONT = rel/apple/HGRFONT\#FE1000 +LINES = rel/LINES\#FE1000 GRAFIX = rel/apple/GRAFIX\#FE1000 +SFM = rel/apple/SFM\#FE1000 +SFMSPRT = rel/apple/SFMSPRT\#FE1000 GFXDEMO = rel/apple/GFXDEMO\#FE1000 JOYBUZZ = rel/apple/JOYBUZZ\#FE1000 PORTIO = rel/apple/PORTIO\#FE1000 @@ -56,6 +76,9 @@ ROGUE = rel/ROGUE\#FE1000 ROGUEMAP = rel/ROGUEMAP\#FE1000 ROGUECOMBAT= rel/ROGUECOMBAT\#FE1000 MON = rel/apple/MON\#FE1000 +TILETEST = rel/apple/TILETEST\#FE1000 +HGRTEST = rel/apple/HGRTEST\#FE1000 +GRTEST = rel/apple/GRTEST\#FE1000 DGRTEST = rel/apple/DGRTEST\#FE1000 MEMMGR = rel/MEMMGR\#FE1000 MEMTEST = rel/MEMTEST\#FE1000 @@ -86,7 +109,8 @@ TXTTYPE = .TXT #SYSTYPE = \#FF2000 #TXTTYPE = \#040000 -apple: $(PLVMZP_APL) $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVMJIT) $(PLVM802) $(PLVM03) $(CMD) $(CMDJIT) $(JIT) $(JIT16) $(JITUNE) $(SOSCMD) $(PLASMAPLASM) $(CODEOPT) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(FIBERTEST) $(LONGJMP) $(ED) $(MON) $(SOS) $(ROD) $(SIEVE) $(PRIMEGAP) $(MOUSE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(TFTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(GRAFIX) $(GFXDEMO) $(DGR) $(DGRTEST) $(FILEIO_APL) $(CONIO_APL) $(JOYBUZZ) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(SANE) $(FPSTR) $(FPU) $(SANITY) $(LZ4) $(LZ4CAT) $(RPNCALC) $(SNDSEQ) $(PLAYSEQ) +apple: $(PLVMZP_APL) $(PLASM) $(PLVM) $(PLVM01) $(PLVM02) $(PLVMJIT) $(PLVM802) $(PLVM03) $(PLVMJIT03) $(CMD) $(CMDJIT) $(JIT) $(JIT16) $(JITUNE) $(SOSCMD) $(SOSCMDJIT) $(PLASMAPLASM) $(CODEOPT) $(ZIP) $(MATCHFILES) $(ARGS) $(MEMMGR) $(MEMTEST) $(FIBER) $(FIBERTEST) $(LONGJMP) $(ED) $(MON) $(COPY) $(DEL) $(REN) $(CAT) $(NEWDIR) $(TYPE) $(SOS) $(ROD) $(SIEVE) $(PRIMEGAP) $(MOUSE) $(UTHERNET2) $(UTHERNET) $(ETHERIP) $(INET) $(DHCP) $(HTTPD) $(TFTPD) $(ROGUE) $(ROGUEMAP) $(ROGUECOMBAT) $(SFM) $(SFMSPRT) $(GRAFIX) $(GFXDEMO) $(LINES) $(HGRTILE) $(HGRFONT) $(HGRSPRITE) $(HGRLIB) $(TILETEST) $(HGRTEST) $(GRLIB) $(DGRLIB) $(GRTEST) $(DGRTEST) $(HGRTEST) $(FILEIO_APL) $(CONIO_APL) $(JOYBUZZ) $(PORTIO) $(SPIPORT) $(SDFAT) $(FATCAT) $(FATGET) $(FATPUT) $(FATWDSK) $(FATRDSK) $(INT32) $(INT32TEST) $(SANE) $(FPSTR) $(FPU) $(SANITY) $(LZ4) $(LZ4CAT) $(RPNCALC) $(SNDSEQ) $(PLAYSEQ) + -rm vmsrc/plvmzp.inc c64: $(PLVMZP_C64) $(PLASM) $(PLVM) $(PLVMC64) @@ -107,7 +131,9 @@ clean: -rm libsrc/*.o libsrc/*~ libsrc/*.a -rm libsrc/apple/*.o libsrc/apple/*~ libsrc/apple/*.a -rm libsrc/c64/*.o libsrc/c64/*~ libsrc/c64/*.a - -rm libsrc/*.o libsrc/*~ libsrc/*.a + -rm utilsrc/*.o utilsrc/*~ utilsrc/*.a + -rm utilsrc/apple/*.o utilsrc/apple/*~ utilsrc/apple/*.a + -rm utilsrc/c64/*.o utilsrc/c64/*~ utilsrc/c64/*.a # # PLASMA compiler: plasm @@ -163,10 +189,14 @@ $(CMDJIT): vmsrc/apple/cmdjit.pla vmsrc/apple/cmdjitstub.s $(PLVMJIT) $(PLASM) ./$(PLASM) -AOW < vmsrc/apple/cmdjit.pla > vmsrc/apple/cmdjit.a acme --setpc 8192 -o $(CMDJIT) vmsrc/apple/cmdjitstub.s -$(SOSCMD): vmsrc/apple/soscmd.pla libsrc/jitcore.pla $(PLVM03) $(PLASM) +$(SOSCMD): vmsrc/apple/soscmd.pla $(PLVM03) $(PLASM) ./$(PLASM) -AMOW < vmsrc/apple/soscmd.pla > vmsrc/apple/soscmd.a acme --setpc 4094 -o $(SOSCMD) vmsrc/apple/soscmd.a +$(SOSCMDJIT): vmsrc/apple/soscmdjit.pla libsrc/jitcore.pla $(PLVMJIT03) $(PLASM) + ./$(PLASM) -AMOW < vmsrc/apple/soscmdjit.pla > vmsrc/apple/soscmdjit.a + acme --setpc 4094 -o $(SOSCMDJIT) vmsrc/apple/soscmdjit.a + $(PLVM02): vmsrc/apple/plvm02.s acme -o $(PLVM02) -l vmsrc/apple/plvm02.sym vmsrc/apple/plvm02.s @@ -182,6 +212,11 @@ vmsrc/apple/sossys.a: vmsrc/apple/sossys.pla $(PLASM) $(PLVM03): vmsrc/apple/plvm03.s vmsrc/apple/sossys.a acme -o $(PLVM03) -l vmsrc/apple/plvm03.sym vmsrc/apple/plvm03.s +vmsrc/apple/sossysjit.a: vmsrc/apple/sossysjit.pla $(PLASM) + ./$(PLASM) -AOW < vmsrc/apple/sossysjit.pla > vmsrc/apple/sossysjit.a + +$(PLVMJIT03): vmsrc/apple/plvmjit03.s vmsrc/apple/sossysjit.a + acme -o $(PLVMJIT03) -l vmsrc/apple/plvmjit03.sym vmsrc/apple/plvmjit03.s # # Sample code # @@ -196,6 +231,10 @@ $(ED): toolsrc/ed.pla $(PLVM02) $(PLASM) toolsrc/ed.pla ./$(PLASM) -AMOW < toolsrc/ed.pla > toolsrc/ed.a acme --setpc 4094 -o $(ED) toolsrc/ed.a +$(MATCHFILES): libsrc/apple/matchfiles.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < libsrc/apple/matchfiles.pla > libsrc/apple/matchfiles.a + acme --setpc 4094 -o $(MATCHFILES) libsrc/apple/matchfiles.a + $(ARGS): libsrc/args.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < libsrc/args.pla > libsrc/args.a acme --setpc 4094 -o $(ARGS) libsrc/args.a @@ -212,6 +251,10 @@ $(FIBER): libsrc/fiber.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < libsrc/fiber.pla > libsrc/fiber.a acme --setpc 4094 -o $(FIBER) libsrc/fiber.a +$(LINES): libsrc/lines.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < libsrc/lines.pla > libsrc/lines.a + acme --setpc 4094 -o $(LINES) libsrc/lines.a + $(FIBERTEST): samplesrc/fibertest.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < samplesrc/fibertest.pla > samplesrc/fibertest.a acme --setpc 4094 -o $(FIBERTEST) samplesrc/fibertest.a @@ -220,6 +263,14 @@ $(LONGJMP): libsrc/longjmp.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < libsrc/longjmp.pla > libsrc/longjmp.a acme --setpc 4094 -o $(LONGJMP) libsrc/longjmp.a +$(SFM): samplesrc/sfm.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < samplesrc/sfm.pla > samplesrc/sfm.a + acme --setpc 4094 -o $(SFM) samplesrc/sfm.a + +$(SFMSPRT): samplesrc/sfmsprt.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < samplesrc/sfmsprt.pla > samplesrc/sfmsprt.a + acme --setpc 4094 -o $(SFMSPRT) samplesrc/sfmsprt.a + $(ROGUE): samplesrc/rogue.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < samplesrc/rogue.pla > samplesrc/rogue.a acme --setpc 4094 -o $(ROGUE) samplesrc/rogue.a @@ -248,6 +299,14 @@ $(PRIMEGAP): samplesrc/primegap.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMW < samplesrc/primegap.pla > samplesrc/primegap.a acme --setpc 4094 -o $(PRIMEGAP) samplesrc/primegap.a +$(INT32): libsrc/int32.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < libsrc/int32.pla > libsrc/int32.a + acme --setpc 4094 -o $(INT32) libsrc/int32.a + +$(INT32TEST): samplesrc/int32test.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < samplesrc/int32test.pla > samplesrc/int32test.a + acme --setpc 4094 -o $(INT32TEST) samplesrc/int32test.a + $(SANE): libsrc/sane.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < libsrc/sane.pla > libsrc/sane.a acme --setpc 4094 -o $(SANE) libsrc/sane.a @@ -292,9 +351,9 @@ $(HTTPD): samplesrc/httpd.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < samplesrc/httpd.pla > samplesrc/httpd.a acme --setpc 4094 -o $(HTTPD) samplesrc/httpd.a -$(TFTPD): samplesrc/tftpd.pla $(PLVM02) $(PLASM) - ./$(PLASM) -AMOW < samplesrc/tftpd.pla > samplesrc/tftpd.a - acme --setpc 4094 -o $(TFTPD) samplesrc/tftpd.a +$(TFTPD): utilsrc/tftpd.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < utilsrc/tftpd.pla > utilsrc/tftpd.a + acme --setpc 4094 -o $(TFTPD) utilsrc/tftpd.a $(MOUSE): libsrc/apple/mouse.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < libsrc/apple/mouse.pla > libsrc/apple/mouse.a @@ -376,21 +435,81 @@ $(PORTIO): libsrc/apple/portio.pla $(PLVM02) $(PLASM) ./$(PLASM) -AMOW < libsrc/apple/portio.pla > libsrc/apple/portio.a acme --setpc 4094 -o $(PORTIO) libsrc/apple/portio.a -$(DGR): libsrc/apple/dgr.pla $(PLVM02) $(PLASM) - ./$(PLASM) -AMOW < libsrc/apple/dgr.pla > libsrc/apple/dgr.a - acme --setpc 4094 -o $(DGR) libsrc/apple/dgr.a +$(HGRLIB): libsrc/apple/hgrlib.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < libsrc/apple/hgrlib.pla > libsrc/apple/hgrlib.a + acme --setpc 4094 -o $(HGRLIB) libsrc/apple/hgrlib.a -$(DGRTEST): samplesrc/dgrtest.pla $(PLVM02) $(PLASM) +$(GRLIB): libsrc/apple/grlib.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < libsrc/apple/grlib.pla > libsrc/apple/grlib.a + acme --setpc 4094 -o $(GRLIB) libsrc/apple/grlib.a + +$(DGRLIB): libsrc/apple/dgrlib.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < libsrc/apple/dgrlib.pla > libsrc/apple/dgrlib.a + acme --setpc 4094 -o $(DGRLIB) libsrc/apple/dgrlib.a + +$(TILETEST): samplesrc/tiletest.pla $(PLASM) + ./$(PLASM) -AMOW < samplesrc/tiletest.pla > samplesrc/tiletest.a + acme --setpc 4094 -o $(TILETEST) samplesrc/tiletest.a + +$(HGRTILE): libsrc/apple/hgrtile.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < libsrc/apple/hgrtile.pla > libsrc/apple/hgrtile.a + acme --setpc 4094 -o $(HGRTILE) libsrc/apple/hgrtile.a + +$(HGRFONT): libsrc/apple/hgrfont.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < libsrc/apple/hgrfont.pla > libsrc/apple/hgrfont.a + acme --setpc 4094 -o $(HGRFONT) libsrc/apple/hgrfont.a + +$(HGRSPRITE): libsrc/apple/hgrsprite.pla $(PLVM02) $(PLASM) + ./$(PLASM) -AMOW < libsrc/apple/hgrsprite.pla > libsrc/apple/hgrsprite.a + acme --setpc 4094 -o $(HGRSPRITE) libsrc/apple/hgrsprite.a + +$(HGRTEST): samplesrc/hgrtest.pla $(HGRLIB) $(PLASM) + ./$(PLASM) -AMOW < samplesrc/hgrtest.pla > samplesrc/hgrtest.a + acme --setpc 4094 -o $(HGRTEST) samplesrc/hgrtest.a + +$(GRTEST): samplesrc/grtest.pla $(GRLIB) $(PLASM) + ./$(PLASM) -AMOW < samplesrc/grtest.pla > samplesrc/grtest.a + acme --setpc 4094 -o $(GRTEST) samplesrc/grtest.a + +$(DGRTEST): samplesrc/dgrtest.pla $(DGRLIB) $(PLASM) ./$(PLASM) -AMOW < samplesrc/dgrtest.pla > samplesrc/dgrtest.a acme --setpc 4094 -o $(DGRTEST) samplesrc/dgrtest.a -$(MON): samplesrc/mon.pla $(PLVM02) $(PLASM) - ./$(PLASM) -AMOW < samplesrc/mon.pla > samplesrc/mon.a - acme --setpc 4094 -o $(MON) samplesrc/mon.a +$(MON): utilsrc/apple/mon.pla $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/mon.pla > utilsrc/apple/mon.a + acme --setpc 4094 -o $(MON) utilsrc/apple/mon.a -$(SOS): libsrc/apple/sos.pla $(PLVM03) $(PLASM) - ./$(PLASM) -AMOW < libsrc/apple/sos.pla > libsrc/apple/sos.a - acme --setpc 4094 -o $(SOS) libsrc/apple/sos.a +$(COPY): utilsrc/apple/copy.pla $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/copy.pla > utilsrc/apple/copy.a + acme --setpc 4094 -o $(COPY) utilsrc/apple/copy.a + +$(DEL): utilsrc/apple/del.pla $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/del.pla > utilsrc/apple/del.a + acme --setpc 4094 -o $(DEL) utilsrc/apple/del.a + +$(REN): utilsrc/apple/ren.pla $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/ren.pla > utilsrc/apple/ren.a + acme --setpc 4094 -o $(REN) utilsrc/apple/ren.a + +$(CAT): utilsrc/apple/cat.pla $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/cat.pla > utilsrc/apple/cat.a + acme --setpc 4094 -o $(CAT) utilsrc/apple/cat.a + +$(NEWDIR): utilsrc/apple/newdir.pla $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/newdir.pla > utilsrc/apple/newdir.a + acme --setpc 4094 -o $(NEWDIR) utilsrc/apple/newdir.a + +$(TYPE): utilsrc/apple/type.pla $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/type.pla > utilsrc/apple/type.a + acme --setpc 4094 -o $(TYPE) utilsrc/apple/type.a + +$(SOS): utilsrc/apple/sos.pla $(PLVM03) $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/sos.pla > utilsrc/apple/sos.a + acme --setpc 4094 -o $(SOS) utilsrc/apple/sos.a + +$(ZIP): utilsrc/apple/zip.pla $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/zip.pla > utilsrc/apple/zip.a + acme --setpc 4094 -o $(ZIP) utilsrc/apple/zip.a $(JIT): libsrc/apple/jit.pla libsrc/jitcore.pla $(PLVMJIT) $(PLASM) ./$(PLASM) -AMOW < libsrc/apple/jit.pla > libsrc/apple/jit.a @@ -400,8 +519,8 @@ $(JIT16): libsrc/apple/jit16.pla libsrc/jit16core.pla $(PLVMJIT) $(PLASM) ./$(PLASM) -AMOW < libsrc/apple/jit16.pla > libsrc/apple/jit16.a acme --setpc 4094 -o $(JIT16) libsrc/apple/jit16.a -$(JITUNE): libsrc/apple/jitune.pla $(PLVMJIT) $(PLASM) - ./$(PLASM) -AMOW < libsrc/apple/jitune.pla > libsrc/apple/jitune.a - acme --setpc 4094 -o $(JITUNE) libsrc/apple/jitune.a +$(JITUNE): utilsrc/apple/jitune.pla $(PLVMJIT) $(PLASM) + ./$(PLASM) -AMOW < utilsrc/apple/jitune.pla > utilsrc/apple/jitune.a + acme --setpc 4094 -o $(JITUNE) utilsrc/apple/jitune.a diff --git a/src/mkrel b/src/mkrel index e1ad102..5a559bf 100755 --- a/src/mkrel +++ b/src/mkrel @@ -1,84 +1,114 @@ -cp rel/apple/CMD#061000 prodos/CMD.BIN -cp rel/apple/CMD128#061000 prodos/CMD128.BIN +cp rel/apple/CMD#061000 prodos/CMD.BIN +cp rel/apple/CMD128#061000 prodos/CMD128.BIN cp rel/apple/PLASMA.SYSTEM#FF2000 prodos/PLASMA.SYSTEM.SYS -cp rel/apple/PLVM.128#FF2000 prodos/PLVM.128.SYS -cp rel/apple/PLVM16#FF2000 prodos/PLVM16.SYS -cp ../doc/Editor.md prodos/EDITOR.README.TXT +cp rel/apple/PLVM.128#FF2000 prodos/PLVM.128.SYS +cp rel/apple/PLVM16#FF2000 prodos/PLVM16.SYS +cp ../doc/Editor.md prodos/EDITOR.README.TXT rm -rf prodos/sys mkdir prodos/sys -cp rel/apple/FILEIO#FE1000 prodos/sys/FILEIO.REL -cp rel/apple/CONIO#FE1000 prodos/sys/CONIO.REL -cp rel/apple/DGR#FE1000 prodos/sys/DGR.REL -cp rel/ARGS#FE1000 prodos/sys/ARGS.REL -cp rel/ED#FE1000 prodos/sys/ED.REL -cp rel/FIBER#FE1000 prodos/sys/FIBER.REL -cp rel/LONGJMP#FE1000 prodos/sys/LONGJMP.REL -cp rel/MEMMGR#FE1000 prodos/sys/MEMMGR.REL -cp rel/INET#FE1000 prodos/sys/INET.REL -cp rel/DHCP#FE1000 prodos/sys/DHCP.REL -cp rel/ETHERIP#FE1000 prodos/sys/ETHERIP.REL -cp rel/apple/MOUSE#FE1000 prodos/sys/MOUSE.REL -cp rel/apple/UTHERNET2#FE1000 prodos/sys/UTHERNET2.REL -cp rel/apple/UTHERNET#FE1000 prodos/sys/UTHERNET.REL -cp rel/apple/PORTIO#FE1000 prodos/sys/PORTIO.REL -cp rel/apple/JOYBUZZ#FE1000 prodos/sys/JOYBUZZ.REL -cp rel/apple/SDFAT#FE1000 prodos/sys/SDFAT.REL -cp rel/apple/SPIPORT#FE1000 prodos/sys/SPIPORT.REL -cp rel/apple/SNDSEQ#FE1000 prodos/sys/SNDSEQ.REL -cp rel/apple/JIT#FE1000 prodos/sys/JIT.REL -cp rel/apple/JIT16#FE1000 prodos/sys/JIT16.REL -cp rel/apple/JITUNE#FE1000 prodos/sys/JITUNE.REL -cp rel/LZ4#FE1000 prodos/sys/LZ4.REL -#cp rel/FPSTR#FE1000 prodos/sys/FPSTR.REL -#cp rel/FPU#FE1000 prodos/sys/FPU.REL -#cp rel/SANE#FE1000 prodos/sys/SANE.REL -#cp ../sysfiles/FP6502.CODE#060000 prodos/sys/FP6502.CODE.BIN -#cp ../sysfiles/ELEMS.CODE#060000 prodos/sys/ELEMS.CODE.BIN +cp rel/apple/FILEIO#FE1000 prodos/sys/FILEIO.REL +cp rel/apple/CONIO#FE1000 prodos/sys/CONIO.REL +cp rel/LINES#FE1000 prodos/sys/LINES.REL +cp rel/apple/HGRFONT#FE1000 prodos/sys/HGRFONT.REL +cp rel/apple/HGRTILE#FE1000 prodos/sys/HGRTILE.REL +cp rel/apple/HGRSPRITE#FE1000 prodos/sys/HGRSPRITE.REL +cp rel/apple/HGRLIB#FE1000 prodos/sys/HGRLIB.REL +cp rel/apple/GRLIB#FE1000 prodos/sys/GRLIB.REL +cp rel/apple/DGRLIB#FE1000 prodos/sys/DGRLIB.REL +cp rel/apple/COPY#FE1000 prodos/sys/COPY.REL +cp rel/apple/DEL#FE1000 prodos/sys/DEL.REL +cp rel/apple/REN#FE1000 prodos/sys/REN.REL +cp rel/apple/CAT#FE1000 prodos/sys/CAT.REL +cp rel/apple/NEWDIR#FE1000 prodos/sys/NEWDIR.REL +cp rel/apple/TYPE#FE1000 prodos/sys/TYPE.REL +cp rel/apple/MATCHFILES#FE1000 prodos/sys/MATCHFILES.REL +cp rel/ARGS#FE1000 prodos/sys/ARGS.REL +cp rel/ED#FE1000 prodos/sys/ED.REL +cp rel/FIBER#FE1000 prodos/sys/FIBER.REL +cp rel/LONGJMP#FE1000 prodos/sys/LONGJMP.REL +cp rel/MEMMGR#FE1000 prodos/sys/MEMMGR.REL +cp rel/INET#FE1000 prodos/sys/INET.REL +cp rel/DHCP#FE1000 prodos/sys/DHCP.REL +cp rel/ETHERIP#FE1000 prodos/sys/ETHERIP.REL +cp rel/apple/MOUSE#FE1000 prodos/sys/MOUSE.REL +cp rel/apple/UTHERNET2#FE1000 prodos/sys/UTHERNET2.REL +cp rel/apple/UTHERNET#FE1000 prodos/sys/UTHERNET.REL +cp rel/apple/PORTIO#FE1000 prodos/sys/PORTIO.REL +cp rel/apple/JOYBUZZ#FE1000 prodos/sys/JOYBUZZ.REL +cp rel/apple/SNDSEQ#FE1000 prodos/sys/SNDSEQ.REL +cp rel/apple/JIT#FE1000 prodos/sys/JIT.REL +cp rel/apple/JIT16#FE1000 prodos/sys/JIT16.REL +cp rel/apple/JITUNE#FE1000 prodos/sys/JITUNE.REL +cp rel/apple/ZIP#FE1000 prodos/sys/ZIP.REL +cp rel/LZ4#FE1000 prodos/sys/LZ4.REL +cp rel/TFTPD#FE1000 prodos/sys/TFTPD.REL +cp rel/INT32#FE1000 prodos/sys/INT32.REL +cp rel/FPSTR#FE1000 prodos/sys/FPSTR.REL +cp rel/FPU#FE1000 prodos/sys/FPU.REL +cp rel/SANE#FE1000 prodos/sys/SANE.REL +cp ../sysfiles/FP6502.CODE#060000 prodos/sys/FP6502.CODE.BIN +cp ../sysfiles/ELEMS.CODE#060000 prodos/sys/ELEMS.CODE.BIN +cp rel/apple/SOS#FE1000 prodos/sys/SOS.REL +cp rel/apple/GRAFIX#FE1000 prodos/sys/GRAFIX.REL rm -rf prodos/fpsos mkdir prodos/fpsos +cp ../sysfiles/SOS.KERNEL#0C0000 prodos/fpsos/SOS.KERNEL.\$0C +cp ../sysfiles/SOS.DRIVER#0C0000 prodos/fpsos/SOS.DRIVER.\$0C cp rel/apple/SOS.INTERP#050000 prodos/fpsos/SOS.INTERP.\$05 -cp rel/apple/SOS.CMD#FE1000 prodos/fpsos/SOS.CMD.REL +cp rel/apple/SOS.CMD#FE1000 prodos/fpsos/SOS.CMD.REL +cp rel/apple/SOS.INTERPJIT#050000 prodos/fpsos/SOS.INTERPJIT.\$05 +cp rel/apple/SOS.CMDJIT#FE1000 prodos/fpsos/SOS.CMDJIT.REL mkdir prodos/fpsos/sys -cp rel/apple/SOS#FE1000 prodos/fpsos/sys/SOS.REL -cp rel/apple/GRAFIX#FE1000 prodos/fpsos/sys/GRAFIX.REL -cp rel/FPSTR#FE1000 prodos/fpsos/sys/FPSTR.REL -cp rel/FPU#FE1000 prodos/fpsos/sys/FPU.REL -cp rel/SANE#FE1000 prodos/fpsos/sys/SANE.REL +cp rel/apple/SOS#FE1000 prodos/fpsos/sys/SOS.REL +cp rel/apple/GRAFIX#FE1000 prodos/fpsos/sys/GRAFIX.REL +cp rel/FPSTR#FE1000 prodos/fpsos/sys/FPSTR.REL +cp rel/FPU#FE1000 prodos/fpsos/sys/FPU.REL +cp rel/SANE#FE1000 prodos/fpsos/sys/SANE.REL cp ../sysfiles/FP6502.CODE#060000 prodos/fpsos/sys/FP6502.CODE.BIN -cp ../sysfiles/ELEMS.CODE#060000 prodos/fpsos/sys/ELEMS.CODE.BIN +cp ../sysfiles/ELEMS.CODE#060000 prodos/fpsos/sys/ELEMS.CODE.BIN rm -rf prodos/demos mkdir prodos/demos +cp rel/INT32TEST#FE1000 prodos/demos/INT32TEST.REL +cp rel/apple/TILETEST#FE1000 prodos/demos/TILETEST.REL +cp rel/apple/HGRTEST#FE1000 prodos/demos/HGRTEST.REL +cp rel/apple/GRTEST#FE1000 prodos/demos/GRTEST.REL cp rel/apple/DGRTEST#FE1000 prodos/demos/DGRTEST.REL -cp rel/RPNCALC#FE1000 prodos/demos/RPNCALC.REL -cp rel/LZ4CAT#FE1000 prodos/demos/LZ4CAT.REL -cp rel/ROD#FE1000 prodos/demos/ROD.REL -cp rel/PRIMEGAP#FE1000 prodos/demos/PRIMEGAP.REL +cp rel/apple/HGRTEST#FE1000 prodos/demos/HGRTEST.REL +cp rel/apple/ROD#FE1000 prodos/demos/ROD.REL +cp rel/RPNCALC#FE1000 prodos/demos/RPNCALC.REL +cp rel/LZ4CAT#FE1000 prodos/demos/LZ4CAT.REL +cp rel/PRIMEGAP#FE1000 prodos/demos/PRIMEGAP.REL + +mkdir prodos/demos/spiders +cp rel/apple/SFM#FE1000 prodos/demos/spiders/SFM.REL +cp rel/apple/SFMSPRT#FE1000 prodos/demos/spiders/SFMSPRT.REL mkdir prodos/demos/rogue -cp rel/ROGUE#FE1000 prodos/demos/rogue/ROGUE.REL -cp rel/ROGUECOMBAT#FE1000 prodos/demos/rogue/ROGUECOMBAT.REL -cp rel/ROGUEMAP#FE1000 prodos/demos/rogue/ROGUEMAP.REL +cp rel/ROGUE#FE1000 prodos/demos/rogue/ROGUE.REL +cp rel/ROGUECOMBAT#FE1000 prodos/demos/rogue/ROGUECOMBAT.REL +cp rel/ROGUEMAP#FE1000 prodos/demos/rogue/ROGUEMAP.REL cp samplesrc/LEVEL0#040000 prodos/demos/rogue/LEVEL0.TXT cp samplesrc/LEVEL1#040000 prodos/demos/rogue/LEVEL1.TXT mkdir prodos/demos/sdutils -cp rel/apple/FATCAT#FE1000 prodos/demos/sdutils/FATCAT.REL -cp rel/apple/FATGET#FE1000 prodos/demos/sdutils/FATGET.REL -cp rel/apple/FATPUT#FE1000 prodos/demos/sdutils/FATPUT.REL -cp rel/apple/FATREADDSK#FE1000 prodos/demos/sdutils/FATREADDSK.REL +cp rel/apple/SPIPORT#FE1000 prodos/demos/sdutils/SPIPORT.REL +cp rel/apple/SDFAT#FE1000 prodos/demos/sdutils/SDFAT.REL +cp rel/apple/FATCAT#FE1000 prodos/demos/sdutils/FATCAT.REL +cp rel/apple/FATGET#FE1000 prodos/demos/sdutils/FATGET.REL +cp rel/apple/FATPUT#FE1000 prodos/demos/sdutils/FATPUT.REL +cp rel/apple/FATREADDSK#FE1000 prodos/demos/sdutils/FATREADDSK.REL cp rel/apple/FATWRITEDSK#FE1000 prodos/demos/sdutils/FATWRITEDSK.REL mkdir prodos/demos/apple3 -cp rel/apple/GFXDEMO#FE1000 prodos/demos/apple3/GFXDEMO.REL +cp rel/apple/GFXDEMO#FE1000 prodos/demos/apple3/GFXDEMO.REL cp samplesrc/APPLE3.PIX#060000 prodos/demos/apple3/APPLE3.PIX.BIN mkdir prodos/demos/net -cp rel/TFTPD#FE1000 prodos/demos/net/TFTPD.REL -cp rel/HTTPD#FE1000 prodos/demos/net/HTTPD.REL +cp rel/HTTPD#FE1000 prodos/demos/net/HTTPD.REL cp samplesrc/index.html prodos/demos/net/INDEX.HTML.TXT mkdir prodos/demos/music @@ -88,46 +118,78 @@ cp mockingboard/startrek.seq prodos/demos/music/STARTREK.SEQ.BIN rm -rf prodos/bld mkdir prodos/bld -cp rel/PLASM#FE1000 prodos/bld/PLASM.REL -cp rel/CODEOPT#FE1000 prodos/bld/CODEOPT.REL -cp samplesrc/dgrtest.pla prodos/bld/DGRTEST.PLA.TXT -cp samplesrc/hello.pla prodos/bld/HELLO.PLA.TXT -cp samplesrc/hgr1test.pla prodos/bld/HGR1TEST.PLA.TXT -cp samplesrc/fibertest.pla prodos/bld/FIBERTEST.PLA.TXT -cp samplesrc/mousetest.pla prodos/bld/MOUSETEST.PLA.TXT -cp samplesrc/mon.pla prodos/bld/MON.PLA.TXT -cp samplesrc/memtest.pla prodos/bld/MEMTEST.PLA.TXT -cp samplesrc/rod.pla prodos/bld/ROD.PLA.TXT -cp samplesrc/sieve.pla prodos/bld/SIEVE.PLA.TXT -cp samplesrc/test.pla prodos/bld/TEST.PLA.TXT -cp samplesrc/testlib.pla prodos/bld/TESTLIB.PLA.TXT -cp samplesrc/playseq.pla prodos/bld/PLAYSEQ.PLA.TXT -cp samplesrc/rpncalc.pla prodos/bld/RPNCALC.PLA.TXT -cp samplesrc/httpd.pla prodos/bld/HTTPD.PLA.TXT -cp samplesrc/fatcat.pla prodos/bld/FATCAT.PLA.TXT -cp samplesrc/gfxdemo.pla prodos/bld/GFXDEMO.PLA.TXT -cp samplesrc/lz4cat.pla prodos/bld/LZ4CAT.PLA.TXT +cp rel/PLASM#FE1000 prodos/bld/PLASM.REL +cp rel/CODEOPT#FE1000 prodos/bld/CODEOPT.REL + +mkdir prodos/bld/samples +cp samplesrc/hello.pla prodos/bld/samples/HELLO.PLA.TXT +cp samplesrc/int32test.pla prodos/bld/samples/INT32TEST.PLA.TXT +cp samplesrc/grtest.pla prodos/bld/samples/GRTEST.PLA.TXT +cp samplesrc/dgrtest.pla prodos/bld/samples/DGRTEST.PLA.TXT +cp samplesrc/hgrtest.pla prodos/bld/samples/HGRTEST.PLA.TXT +cp samplesrc/tiletest.pla prodos/bld/samples/TILETEST.PLA.TXT +cp samplesrc/fibertest.pla prodos/bld/samples/FIBERTEST.PLA.TXT +cp samplesrc/mousetest.pla prodos/bld/samples/MOUSETEST.PLA.TXT +cp samplesrc/memtest.pla prodos/bld/samples/MEMTEST.PLA.TXT +cp samplesrc/rod.pla prodos/bld/samples/ROD.PLA.TXT +cp samplesrc/sieve.pla prodos/bld/samples/SIEVE.PLA.TXT +cp samplesrc/test.pla prodos/bld/samples/TEST.PLA.TXT +cp samplesrc/testlib.pla prodos/bld/samples/TESTLIB.PLA.TXT +cp samplesrc/playseq.pla prodos/bld/samples/PLAYSEQ.PLA.TXT +cp samplesrc/rpncalc.pla prodos/bld/samples/RPNCALC.PLA.TXT +cp samplesrc/fatcat.pla prodos/bld/samples/FATCAT.PLA.TXT +cp samplesrc/gfxdemo.pla prodos/bld/samples/GFXDEMO.PLA.TXT +cp samplesrc/lz4cat.pla prodos/bld/samples/Z4CAT.PLA.TXT +cp samplesrc/sfm.pla prodos/bld/samples/SFM.PLA.TXT +cp samplesrc/sfmsprt.pla prodos/bld/samples/SFMSPRT.PLA.TXT + +#mkdir prodos/bld/examples +#cp samplesrc/examples/ex.1.pla prodos/bld/examples/EX.1.PLA.TXT +#cp samplesrc/examples/ex.2.pla prodos/bld/examples/EX.2.PLA.TXT +#cp samplesrc/examples/ex.3.pla prodos/bld/examples/EX.3.PLA.TXT +#cp samplesrc/examples/ex.4.pla prodos/bld/examples/EX.4.PLA.TXT +#cp samplesrc/examples/ex.5.pla prodos/bld/examples/EX.5.PLA.TXT +#cp samplesrc/examples/ex.6.pla prodos/bld/examples/EX.6.PLA.TXT +#cp samplesrc/examples/ex.7.pla prodos/bld/examples/EX.7.PLA.TXT +#cp samplesrc/examples/ex.8.pla prodos/bld/examples/EX.8.PLA.TXT +#cp samplesrc/examples/ex.9.pla prodos/bld/examples/EX.9.PLA.TXT +#cp samplesrc/examples/ex.10.pla prodos/bld/examples/EX.10.PLA.TXT +#cp samplesrc/examples/ex.11.pla prodos/bld/examples/EX.11.PLA.TXT +#cp samplesrc/examples/ex.12.pla prodos/bld/examples/EX.12.PLA.TXT +#cp samplesrc/examples/ex.13.pla prodos/bld/examples/EX.13.PLA.TXT +#cp samplesrc/examples/ex.14.pla prodos/bld/examples/EX.14.PLA.TXT +#cp samplesrc/examples/ex.15.pla prodos/bld/examples/EX.15.PLA.TXT +#cp samplesrc/examples/ex.16.pla prodos/bld/examples/EX.16.PLA.TXT +#cp samplesrc/examples/ex.17.pla prodos/bld/examples/EX.17.PLA.TXT mkdir prodos/bld/inc -cp inc/args.plh prodos/bld/inc/ARGS.PLH.TXT -cp inc/cmdsys.plh prodos/bld/inc/CMDSYS.PLH.TXT -cp inc/conio.plh prodos/bld/inc/CONIO.PLH.TXT -cp inc/dgr.plh prodos/bld/inc/DGR.PLH.TXT -cp inc/fiber.plh prodos/bld/inc/FIBER.PLH.TXT -cp inc/fileio.plh prodos/bld/inc/FILEIO.PLH.TXT -cp inc/fpstr.plh prodos/bld/inc/FPSTR.PLH.TXT -cp inc/fpu.plh prodos/bld/inc/FPU.PLH.TXT -cp inc/mouse.plh prodos/bld/inc/MOUSE.PLH.TXT -cp inc/inet.plh prodos/bld/inc/INET.PLH.TXT -cp inc/longjmp.plh prodos/bld/inc/LONGJMP.PLH.TXT -cp inc/memmgr.plh prodos/bld/inc/MEMMGR.PLH.TXT -cp inc/sane.plh prodos/bld/inc/SANE.PLH.TXT -cp inc/joybuzz.plh prodos/bld/inc/JOYBUZZ.PLH.TXT -cp inc/portio.plh prodos/bld/inc/PORTIO.PLH.TXT -cp inc/sdfat.plh prodos/bld/inc/SDFAT.PLH.TXT -cp inc/sndseq.plh prodos/bld/inc/SNDSEQ.PLH.TXT -cp inc/spiport.plh prodos/bld/inc/SPIPORT.PLH.TXT -cp inc/testlib.plh prodos/bld/inc/TESTLIB.PLH.TXT -cp inc/grafix.plh prodos/bld/inc/GRAFIX.PLH.TXT -cp inc/lz4.plh prodos/bld/inc/LZ4.PLH.TXT +cp inc/args.plh prodos/bld/inc/ARGS.PLH.TXT +cp inc/matchfiles.plh prodos/bld/inc/MATCHFILES.PLH.TXT +cp inc/cmdsys.plh prodos/bld/inc/CMDSYS.PLH.TXT +cp inc/conio.plh prodos/bld/inc/CONIO.PLH.TXT +cp inc/lines.plh prodos/bld/inc/LINES.PLH.TXT +cp inc/hgrfont.plh prodos/bld/inc/HGRFONT.PLH.TXT +cp inc/hgrtile.plh prodos/bld/inc/HGRTILE.PLH.TXT +cp inc/hgrsprite.plh prodos/bld/inc/HGRSPRITE.PLH.TXT +cp inc/hgrlib.plh prodos/bld/inc/HGRLIB.PLH.TXT +cp inc/grlib.plh prodos/bld/inc/GRLIB.PLH.TXT +cp inc/dgrlib.plh prodos/bld/inc/DGRLIB.PLH.TXT +cp inc/fiber.plh prodos/bld/inc/FIBER.PLH.TXT +cp inc/fileio.plh prodos/bld/inc/FILEIO.PLH.TXT +cp inc/int32.plh prodos/bld/inc/INT32.PLH.TXT +cp inc/fpstr.plh prodos/bld/inc/FPSTR.PLH.TXT +cp inc/fpu.plh prodos/bld/inc/FPU.PLH.TXT +cp inc/mouse.plh prodos/bld/inc/MOUSE.PLH.TXT +cp inc/inet.plh prodos/bld/inc/INET.PLH.TXT +cp inc/longjmp.plh prodos/bld/inc/LONGJMP.PLH.TXT +cp inc/memmgr.plh prodos/bld/inc/MEMMGR.PLH.TXT +cp inc/sane.plh prodos/bld/inc/SANE.PLH.TXT +cp inc/joybuzz.plh prodos/bld/inc/JOYBUZZ.PLH.TXT +cp inc/portio.plh prodos/bld/inc/PORTIO.PLH.TXT +cp inc/sdfat.plh prodos/bld/inc/SDFAT.PLH.TXT +cp inc/sndseq.plh prodos/bld/inc/SNDSEQ.PLH.TXT +cp inc/spiport.plh prodos/bld/inc/SPIPORT.PLH.TXT +cp inc/testlib.plh prodos/bld/inc/TESTLIB.PLH.TXT +cp inc/grafix.plh prodos/bld/inc/GRAFIX.PLH.TXT +cp inc/lz4.plh prodos/bld/inc/LZ4.PLH.TXT cp vmsrc/apple/plvmzp.inc prodos/bld/inc/PLVMZP.INC.TXT diff --git a/src/samplesrc/dgrtest.pla b/src/samplesrc/dgrtest.pla index d3412c6..c5ead35 100644 --- a/src/samplesrc/dgrtest.pla +++ b/src/samplesrc/dgrtest.pla @@ -1,4 +1,7 @@ -include "inc/dgr.plh" +include "inc/cmdsys.plh" +include "inc/dgrlib.plh" +include "inc/lines.plh" +sysflags restxt1|restxt2|resxtxt1|resxtxt2 // Reserve all text pages byte[] sprite1 = $80,$80,$00,$00,$00,$00,$80,$80 byte[] = $80,$00,$0A,$0A,$0A,$0A,$00,$80 @@ -18,42 +21,45 @@ byte[] = $0A,$05,$0A,$05,$0A,$05,$0A,$00 // Test routine // def dgrTest#0 - byte b, l, k - word i, j, ii, ij + byte b, l, k + word i, j, ii, ij - b = dgrMode() - for k = 15 downto 0 - dgrClear(dgrbuff[0], k) - next - for l = 0 to 79 - dgrColor(l) - dgrLine(dgrbuff[0], 0, 0, l, 47) - next - for l = 47 downto 0 - dgrColor(l) - dgrLine(dgrbuff[0], 0, 0, 79, l) - next - ii = 2 - ij = -1 - i = 40 - j = 10 - ^$C010 - while ^$C000 < 128 - dgrFill(dgrbuff[b], k, k, @tile1) - dgrBLT(dgrbuff[b], i, j, 8, 8, @sprite1) - b = dgrShow(b) - k++ - i = i + ii - if i < -3 or i > 75 - ii = -ii - fin - j = j + ij - if j < -3 or j > 43 - ij = -ij - fin - loop - ^$C010 - txtMode + b = dgrMode(TRUE) + dgrDrawBuf(0) + for k = 15 downto 0 + dgrClear(k) + next + setlinespans(@dgrHLin, @dgrVLin) + for l = 0 to 79 + dgrColor(l) + linespans(0, 0, l, 47) + next + for l = 47 downto 0 + dgrColor(l) + linespans(0, 0, 79, l) + next + ii = 2 + ij = -1 + i = 40 + j = 10 + ^$C010 + dgrDrawBuf(1) + while ^$C000 < 128 + dgrFill(k, k, @tile1) + dgrBLT(i, j, 8, 8, @sprite1) + dgrSwap + k++ + i = i + ii + if i < -3 or i > 75 + ii = -ii + fin + j = j + ij + if j < -3 or j > 43 + ij = -ij + fin + loop + ^$C010 + dgrMode(FALSE) end dgrTest diff --git a/src/samplesrc/grtest.pla b/src/samplesrc/grtest.pla new file mode 100644 index 0000000..88880a7 --- /dev/null +++ b/src/samplesrc/grtest.pla @@ -0,0 +1,66 @@ +include "inc/cmdsys.plh" +include "inc/grlib.plh" +include "inc/lines.plh" +sysflags restxt1|restxt2 // Reserve all text pages + +byte[] sprite1 = $80,$80,$00,$00,$00,$00,$80,$80 +byte[] = $80,$00,$0A,$0A,$0A,$0A,$00,$80 +byte[] = $00,$0A,$0F,$0F,$0F,$0F,$0A,$00 +byte[] = $00,$0A,$0F,$80,$80,$0F,$0A,$00 +byte[] = $00,$0A,$0F,$80,$80,$0F,$0A,$00 +byte[] = $00,$0A,$0F,$0F,$0F,$0F,$0A,$00 +byte[] = $80,$00,$0A,$0A,$0A,$0A,$00,$80 +byte[] = $80,$80,$00,$00,$00,$00,$80,$80 + +byte[] tile1 = $11,$11,$11,$11,$11,$11,$55,$00 +byte[] = $11,$11,$11,$11,$11,$11,$55,$00 +byte[] = $11,$11,$11,$11,$11,$11,$55,$00 +byte[] = $05,$05,$05,$05,$05,$05,$05,$00 + +// +// Test routine +// +def grTest#0 + byte b, l, k + word i, j, ii, ij + + b = grMode(TRUE) + grDrawBuf(0) + for k = 15 downto 0 + grClear(k) + next + setlinespans(@grHLin, @grVLin) + for l = 0 to 39 + grColor(l) + linespans(0, 0, l, 47) + next + for l = 47 downto 0 + grColor(l) + linespans(0, 0, 39, l) + next + ii = 2 + ij = -1 + i = 20 + j = 10 + ^$C010 + grDrawBuf(1) + while ^$C000 < 128 + grFill(k, k, @tile1) + grBLT(i, j, 8, 8, @sprite1) + grSwap + k++ + i = i + ii + if i < -3 or i > 35 + ii = -ii + fin + j = j + ij + if j < -3 or j > 43 + ij = -ij + fin + loop + ^$C010 + grMode(FALSE) +end + +grTest +done diff --git a/src/samplesrc/hgr1test.pla b/src/samplesrc/hgr1test.pla deleted file mode 100644 index 41efef9..0000000 --- a/src/samplesrc/hgr1test.pla +++ /dev/null @@ -1,56 +0,0 @@ -include "inc/cmdsys.plh" -sysflags reshgr1 // Reserve HGR page 1 - -// -// Hardware addresses -// -const speaker = $C030 -const showgraphics = $C050 -const showtext = $C051 -const showfull = $C052 -const showmix = $C053 -const showpage1 = $C054 -const showpage2 = $C055 -const showlores = $C056 -const showhires = $C057 -const keyboard = $C000 -const keystrobe = $C010 -const hgr1 = $2000 -const hgr2 = $4000 -const page1 = 0 -const page2 = 1 -word hgrpage[] = hgr1, hgr2 -word hgrscan[] = $0000,$0400,$0800,$0C00,$1000,$1400,$1800,$1C00 -word = $0080,$0480,$0880,$0C80,$1080,$1480,$1880,$1C80 -word = $0100,$0500,$0900,$0D00,$1100,$1500,$1900,$1D00 -word = $0180,$0580,$0980,$0D80,$1180,$1580,$1980,$1D80 -word = $0200,$0600,$0A00,$0E00,$1200,$1600,$1A00,$1E00 -word = $0280,$0680,$0A80,$0E80,$1280,$1680,$1A80,$1E80 -word = $0300,$0700,$0B00,$0F00,$1300,$1700,$1B00,$1F00 -word = $0380,$0780,$0B80,$0F80,$1380,$1780,$1B80,$1F80 -word = $0028,$0428,$0828,$0C28,$1028,$1428,$1828,$1C28 -word = $00A8,$04A8,$08A8,$0CA8,$10A8,$14A8,$18A8,$1CA8 -word = $0128,$0528,$0928,$0D28,$1128,$1528,$1928,$1D28 -word = $01A8,$05A8,$09A8,$0DA8,$11A8,$15A8,$19A8,$1DA8 -word = $0228,$0628,$0A28,$0E28,$1228,$1628,$1A28,$1E28 -word = $02A8,$06A8,$0AA8,$0EA8,$12A8,$16A8,$1AA8,$1EA8 -word = $0328,$0728,$0B28,$0F28,$1328,$1728,$1B28,$1F28 -word = $03A8,$07A8,$0BA8,$0FA8,$13A8,$17A8,$1BA8,$1FA8 -word = $0050,$0450,$0850,$0C50,$1050,$1450,$1850,$1C50 -word = $00D0,$04D0,$08D0,$0CD0,$10D0,$14D0,$18D0,$1CD0 -word = $0150,$0550,$0950,$0D50,$1150,$1550,$1950,$1D50 -word = $01D0,$05D0,$09D0,$0DD0,$11D0,$15D0,$19D0,$1DD0 -word = $0250,$0650,$0A50,$0E50,$1250,$1650,$1A50,$1E50 -word = $02D0,$06D0,$0AD0,$0ED0,$12D0,$16D0,$1AD0,$1ED0 -word = $0350,$0750,$0B50,$0F50,$1350,$1750,$1B50,$1F50 -word = $03D0,$07D0,$0BD0,$0FD0,$13D0,$17D0,$1BD0,$1FD0 -word hcolor[] = $0000,$552A,$2A55,$7F7F,$8080,$D5AA,$AAD5,$FFFF -memset(hgr1, 0, $2000) // Clear HGR page 1 -^showpage1 -^showfull -^showhires -^showgraphics -getc -^showpage1 -^showtext -done diff --git a/src/samplesrc/hgrtest.pla b/src/samplesrc/hgrtest.pla new file mode 100644 index 0000000..64d4080 --- /dev/null +++ b/src/samplesrc/hgrtest.pla @@ -0,0 +1,81 @@ +include "inc/cmdsys.plh" +include "inc/hgrlib.plh" +include "inc/hgrsprite.plh" +include "inc/lines.plh" +sysflags reshgr1|reshgr2 // Reserve HGR page 1 and 2 + +byte ball = $88, $83, $33, $38, $88 +byte = $88, $33, $11, $33, $88 +byte = $83, $31, $11, $13, $38 +byte = $33, $11, $11, $11, $33 +byte = $33, $11, $11, $11, $33 +byte = $33, $11, $11, $11, $33 +byte = $33, $11, $11, $11, $33 +byte = $83, $31, $11, $13, $38 +byte = $88, $33, $11, $33, $88 +byte = $88, $83, $33, $38, $88 +var sprtBall + +def testline#0 + var i + + setlinespans(@hgrHlin, @hgrVlin) + setlineplot(@hgrXorPlot) + hgrColor(7) + for i = 0 to 191 step 8 + linespans(0, i, 279, 191 - i) + //line(0, i, 279, 191 - i) + next + for i = 0 to 279 step 9 + linespans(i, 0, 279 - i, 191) + //line(i, 0, 279 - i, 191) + next +end +def testblt(sprtnum)#0 + var[16] i, j, ii, jj + byte k + + sprtnum = sprtnum - 1 + i[0] = 100 + ii[0] = 1 + j[0] = 80 + jj[0] = -1 + if sprtnum + for k = 1 to sprtnum + spriteAdd(k, spriteDup(sprtBall)) + i[k] = ((i[k - 1] ^ 37) + 97) % 270 + ii[k] = -ii[k - 1] + j[k] = ((j[k - 1] ^ 29) + 53) % 180 + jj[k] = -jj[k - 1] + next + fin + while ^$C000 < 128 + for k = 0 to sprtnum + i[k] = i[k] + ii[k] + if i[k] < -5 or i[k] > 284 + ii[k] = -ii[k] + fin + j[k] = j[k] + jj[k] + if j[k] < -5 or j[k] > 196 + jj[k] = -jj[k] + fin + spritePosIndex(i[k], j[k], k) + next + spriteDrawList() + spriteDrawBuf(hgrSwap()) + loop +end + +hgrMode(TRUE) +spriteDrawBuf(hgrDrawBuf(0)) // So we can see the compile process +sprtBall = spriteCompile(10, 10, 5, 5, @ball) +hgrColor(0) +hgrClear() +testline +memcpy($4000, $2000, $2000) // Copy to both buffers +spriteDrawBuf(hgrDrawBuf(1)) +spriteAdd(0, sprtBall) +testblt(16) +getc +hgrMode(FALSE) +done diff --git a/src/samplesrc/int32test.pla b/src/samplesrc/int32test.pla new file mode 100644 index 0000000..c9c3946 --- /dev/null +++ b/src/samplesrc/int32test.pla @@ -0,0 +1,72 @@ +include "inc/cmdsys.plh" +include "inc/int32.plh" + +def testi32#0 + word il, ih + res[t_i32] i32 + + ih = 0 + for il = 0 to 10 + load32(@il) + muli16(10) + divi16(2) + store32(@i32) + puti32(@i32); putln + next + muli16(-30000) + store32(@i32) + puti32(@i32); putln + loadi16(100) + if islti16(50) + puts("100 < 50\n") + fin + if islti16(500) + puts("100 < 500\n") + fin + if isgti16(50) + puts("100 > 50\n") + fin + if isgti16(500) + puts("100 > 500\n") + fin + if islei16(50) + puts("100 <= 50\n") + fin + if islei16(500) + puts("100 <= 500\n") + fin + if isgei16(50) + puts("100 >= 50\n") + fin + if isgei16(500) + puts("100 >= 500\n") + fin + + if islti16(100) + puts("100 < 100\n") + fin + if islti16(100) + puts("100 < 100\n") + fin + if isgti16(100) + puts("100 > 100\n") + fin + if isgti16(100) + puts("100 > 100\n") + fin + if islei16(100) + puts("100 <= 100\n") + fin + if islei16(100) + puts("100 <= 100\n") + fin + if isgei16(100) + puts("100 >= 100\n") + fin + if isgei16(100) + puts("100 >= 100\n") + fin +end + +testi32 +done diff --git a/src/samplesrc/rogue.map.pla b/src/samplesrc/rogue.map.pla index 0ddf1a9..e9ce3bd 100644 --- a/src/samplesrc/rogue.map.pla +++ b/src/samplesrc/rogue.map.pla @@ -402,7 +402,7 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) // Update distance // occluded = 1 - dist = dist + 1 + dist = dist + 1 fin next break @@ -419,12 +419,12 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if adjtile & OPAQUE_TILE ^(viewmap + imap - mapcols) = adjtile | VIEWED_TILE screen.[ycentr-xbeam[l]-1, xcentr+ybeam[l]] = adjtile - fin + fin fin ^(viewmap + imap) = tile | VIEWED_TILE - if tile <> PIT_TILE + if tile <> PIT_TILE screen.[ycentr-xbeam[l], xcentr+ybeam[l]] = tile & INV_TILE - fin + fin else vispix[l] = 0 fin @@ -437,24 +437,24 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) vispix[l] = 0 else vispix[l] = 1 - occluded = 0 + occluded = 0 fin - if tile & LIT_TILE + if tile & LIT_TILE ^(viewmap + imap) = tile | VIEWED_TILE screen.[ycentr-xbeam[l], xcentr+ybeam[l]] = tile & INV_TILE darkness = 0 - fin + fin else vispix[l] = 0 fin - if l == dbeam[dist] - if occluded - break - fin + if l == dbeam[dist] + if occluded + break + fin occluded = 1 - dist = dist + 1 - fin - next + dist = dist + 1 + fin + next break is 2 for l = 1 to dbeam[lightdist] @@ -464,17 +464,17 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - adjtile = ^(map + imap + mapcols) & INV_TILE + vispix[l] = 1 + adjtile = ^(map + imap + mapcols) & INV_TILE if adjtile & OPAQUE_TILE ^(viewmap + imap + mapcols) = adjtile | VIEWED_TILE screen.[ycentr+xbeam[l]+1, xcentr+ybeam[l]] = adjtile fin - fin + fin ^(viewmap + imap) = tile | VIEWED_TILE - if tile <> PIT_TILE + if tile <> PIT_TILE screen.[ycentr+xbeam[l], xcentr+ybeam[l]] = tile & INV_TILE - fin + fin else vispix[l] = 0 fin @@ -486,25 +486,25 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - occluded = 0 - fin - if tile & LIT_TILE + vispix[l] = 1 + occluded = 0 + fin + if tile & LIT_TILE ^(viewmap + imap) = tile | VIEWED_TILE screen.[ycentr+xbeam[l], xcentr+ybeam[l]] = tile & INV_TILE darkness = 0 - fin + fin else vispix[l] = 0 fin - if l == dbeam[dist] - if occluded - break - fin + if l == dbeam[dist] + if occluded + break + fin occluded = 1 - dist = dist + 1 - fin - next + dist = dist + 1 + fin + next break is 3 for l = 1 to dbeam[lightdist] @@ -514,17 +514,17 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - adjtile = ^(map + imap + 1) & INV_TILE + vispix[l] = 1 + adjtile = ^(map + imap + 1) & INV_TILE if adjtile & OPAQUE_TILE ^(viewmap + imap + 1) = adjtile | VIEWED_TILE screen.[ycentr+ybeam[l], xcentr+xbeam[l]+1] = adjtile fin fin ^(viewmap + imap) = tile | VIEWED_TILE - if tile <> PIT_TILE + if tile <> PIT_TILE screen.[ycentr+ybeam[l], xcentr+xbeam[l]] = tile & INV_TILE - fin + fin else vispix[l] = 0 fin @@ -536,25 +536,25 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - occluded = 0 - fin - if tile & LIT_TILE + vispix[l] = 1 + occluded = 0 + fin + if tile & LIT_TILE ^(viewmap + imap) = tile | VIEWED_TILE screen.[ycentr+ybeam[l], xcentr+xbeam[l]] = tile & INV_TILE darkness = 0 - fin + fin else vispix[l] = 0 fin - if l == dbeam[dist] - if occluded - break - fin + if l == dbeam[dist] + if occluded + break + fin occluded = 1 - dist = dist + 1 - fin - next + dist = dist + 1 + fin + next break is 4 for l = 1 to dbeam[lightdist] @@ -564,17 +564,17 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - adjtile = ^(map + imap - 1) & INV_TILE + vispix[l] = 1 + adjtile = ^(map + imap - 1) & INV_TILE if adjtile & OPAQUE_TILE ^(viewmap + imap - 1) = adjtile | VIEWED_TILE screen.[ycentr+ybeam[l], xcentr-xbeam[l]-1] = adjtile fin fin ^(viewmap + imap) = tile | VIEWED_TILE - if tile <> PIT_TILE + if tile <> PIT_TILE screen.[ycentr+ybeam[l], xcentr-xbeam[l]] = tile & INV_TILE - fin + fin else vispix[l] = 0 fin @@ -586,25 +586,25 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - occluded = 0 - fin - if tile & LIT_TILE + vispix[l] = 1 + occluded = 0 + fin + if tile & LIT_TILE ^(viewmap + imap) = tile | VIEWED_TILE screen.[ycentr+ybeam[l], xcentr-xbeam[l]] = tile & INV_TILE darkness = 0 - fin + fin else vispix[l] = 0 fin - if l == dbeam[dist] - if occluded - break - fin + if l == dbeam[dist] + if occluded + break + fin occluded = 1 - dist = dist + 1 - fin - next + dist = dist + 1 + fin + next break is 5 for l = 1 to dbeam[lightdist] @@ -614,17 +614,17 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - adjtile = ^(map + imap + mapcols) & INV_TILE + vispix[l] = 1 + adjtile = ^(map + imap + mapcols) & INV_TILE if adjtile & OPAQUE_TILE ^(viewmap + imap + mapcols) = adjtile | VIEWED_TILE screen.[ycentr+xbeam[l]+1, xcentr-ybeam[l]] = adjtile fin fin ^(viewmap + imap) = tile | VIEWED_TILE - if tile <> PIT_TILE + if tile <> PIT_TILE screen.[ycentr+xbeam[l], xcentr-ybeam[l]] = tile & INV_TILE - fin + fin else vispix[l] = 0 fin @@ -636,26 +636,26 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - occluded = 0 - fin - if tile & LIT_TILE + vispix[l] = 1 + occluded = 0 + fin + if tile & LIT_TILE ^(viewmap + imap) = tile | VIEWED_TILE screen.[ycentr+xbeam[l], xcentr-ybeam[l]] = tile & INV_TILE darkness = 0 - fin + fin else vispix[l] = 0 fin - if l == dbeam[dist] - if occluded - break - fin + if l == dbeam[dist] + if occluded + break + fin occluded = 1 - dist = dist + 1 - fin - next - break + dist = dist + 1 + fin + next + break is 6 for l = 1 to dbeam[lightdist] if vispix[vbeam[l]] @@ -664,17 +664,17 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - adjtile = ^(map + imap - mapcols) & INV_TILE + vispix[l] = 1 + adjtile = ^(map + imap - mapcols) & INV_TILE if adjtile & OPAQUE_TILE ^(viewmap + imap - mapcols) = adjtile | VIEWED_TILE screen.[ycentr-xbeam[l]-1, xcentr-ybeam[l]] = adjtile fin fin ^(viewmap + imap) = tile | VIEWED_TILE - if tile <> PIT_TILE + if tile <> PIT_TILE screen.[ycentr-xbeam[l], xcentr-ybeam[l]] = tile & INV_TILE - fin + fin else vispix[l] = 0 fin @@ -686,25 +686,25 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - occluded = 0 - fin - if tile & LIT_TILE + vispix[l] = 1 + occluded = 0 + fin + if tile & LIT_TILE ^(viewmap + imap) = tile | VIEWED_TILE screen.[ycentr-xbeam[l], xcentr-ybeam[l]] = tile & INV_TILE darkness = 0 - fin + fin else vispix[l] = 0 fin - if l == dbeam[dist] - if occluded - break - fin + if l == dbeam[dist] + if occluded + break + fin occluded = 1 - dist = dist + 1 - fin - next + dist = dist + 1 + fin + next break is 7 for l = 1 to dbeam[lightdist] @@ -714,17 +714,17 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - adjtile = ^(map + imap - 1) & INV_TILE + vispix[l] = 1 + adjtile = ^(map + imap - 1) & INV_TILE if adjtile & OPAQUE_TILE ^(viewmap + imap - 1) = adjtile | VIEWED_TILE screen.[ycentr-ybeam[l], xcentr-xbeam[l]-1] = adjtile fin fin ^(viewmap + imap) = tile | VIEWED_TILE - if tile <> PIT_TILE + if tile <> PIT_TILE screen.[ycentr-ybeam[l], xcentr-xbeam[l]] = tile & INV_TILE - fin + fin else vispix[l] = 0 fin @@ -736,25 +736,25 @@ export def drawmap(xorg, yorg, viewfield, viewdir, lightdist, viewdist) if tile & OPAQUE_TILE vispix[l] = 0 else - vispix[l] = 1 - occluded = 0 - fin - if tile & LIT_TILE + vispix[l] = 1 + occluded = 0 + fin + if tile & LIT_TILE ^(viewmap + imap) = tile | VIEWED_TILE screen.[ycentr-ybeam[l], xcentr-xbeam[l]] = tile & INV_TILE darkness = 0 - fin + fin else vispix[l] = 0 fin - if l == dbeam[dist] - if occluded - break - fin + if l == dbeam[dist] + if occluded + break + fin occluded = 1 - dist = dist + 1 - fin - next + dist = dist + 1 + fin + next break wend next diff --git a/src/samplesrc/rogue.pla b/src/samplesrc/rogue.pla index d7f115a..add2fc1 100755 --- a/src/samplesrc/rogue.pla +++ b/src/samplesrc/rogue.pla @@ -535,47 +535,47 @@ def play is KEY_TILE player.key = 1 updtmaptile(player.xpos, player.ypos, FLOOR_TILE) - gotit - break + gotit + break is RAFT_TILE player.raft = 1 updtmaptile(player.xpos, player.ypos, FLOOR_TILE) - gotit - break + gotit + break is GOLD_TILE player.gold = player.gold + 1 updtmaptile(player.xpos, player.ypos, FLOOR_TILE) - gotit + gotit break is TORCH_TILE - if player.oil < 1000 + if player.oil < 1000 player:oil = player:oil + TORCH_OIL - if player:oil > 1000 - player:oil = 1000 - fin + if player:oil > 1000 + player:oil = 1000 + fin setmaptile(player.xpos, player.ypos, FLOOR_TILE) for yt = player.ypos - 1 to player.ypos + 1 - for xt = player.xpos - 1 to player.xpos + 1 - setmaptile(xt, yt, getmaptile(xt, yt) & MAP_TILE) - next - next - gotit - fin + for xt = player.xpos - 1 to player.xpos + 1 + setmaptile(xt, yt, getmaptile(xt, yt) & MAP_TILE) + next + next + gotit + fin break is FOOD_TILE - if player.health < 100 or player.energy < 100 + if player.health < 100 or player.energy < 100 player.health = player.health + MANA/2 - if player.health > 100 - player.health = 100 - fin + if player.health > 100 + player.health = 100 + fin player.energy = player.energy + MANA - if player.energy > 100 - player.energy = 100 - fin - updtmaptile(player.xpos, player.ypos, FLOOR_TILE) - player.fov = 1 - gotit - fin + if player.energy > 100 + player.energy = 100 + fin + updtmaptile(player.xpos, player.ypos, FLOOR_TILE) + player.fov = 1 + gotit + fin break wend break diff --git a/src/samplesrc/sfm.pla b/src/samplesrc/sfm.pla new file mode 100644 index 0000000..69396f6 --- /dev/null +++ b/src/samplesrc/sfm.pla @@ -0,0 +1,637 @@ +// +// Ziggy Stardust and the Spiders from Mars +// +include "inc/cmdsys.plh" +include "inc/hgrlib.plh" +include "inc/hgrsprite.plh" +include "inc/joybuzz.plh" +sysflags reshgr1 // Reserve HGR page 1 + +const NUMSTARS = 32 +const SHIP_SPRTNUM = 0 +const MISSLE_SPRTNUM = 1 +const WEB_SPRTBASE = 2 +const SPIDER_SPRTEBASE = 8 +const LASER_RECHARGE = 20 +const MISSLE_RELOAD = 10 +const ATTACK_SPEED = 12 +const SWARM_LIMIT = 52 +const FASTMOVE_LIMIT = 120 +const WEB_LIMIT = 152 +const YSHIP = 180 +const LASER_BUZZ = 20 +const ATTACK_BUZZ = 5 +const WEB1_BUZZ = 10 +const WEB2_BUZZ = 12 +const WEB3_BUZZ = 14 +const SPLAT_BUZZ = 40 + +var sprtEgg1, sprtEgg2, sprtEgg3, sprtEgg +var sprtSpider1, sprtSpider2, sprtSpider3, sprtSpider +var sprtSplat1, sprtSplat2 +var sprtWeb1, sprtWeb2, sprtWeb3 +var sprtShip, sprtMissle, sprtDummy, heapstart +var[NUMSTARS] xstar +byte[NUMSTARS] ystar +byte curstar, buzz + +// +// Apple II speaker tone generator routine +// +//asm spkrTone(pitch, duration)#0 +byte _spkrTone[] +byte = $86, $E5 // STX ESP +byte = $B4, $C0 // LDY ESTKH,X +byte = $B5, $D0 // LDA ESTKL,X +byte = $F0, $01 // BEQ +1 +byte = $C8 // INY +byte = $85, $08 // STA DSTL +byte = $84, $09 // STY DSTH +byte = $B4, $C1 // LDY ESTKL+1,X +byte = $B5, $D1 // LDA ESTKL+1,X +byte = $F0, $01 // BEQ +1 +byte = $C8 // INY +byte = $85, $E7 // STA TMPL +byte = $84, $E8 // STY TMPH +byte = $AA // TAX +byte = $A9, $FF // LDA #$FF +byte = $08 // PHP +byte = $78 // SEI +byte = $EA // NOP +byte = $EA // NOP +byte = $B0, $00 // BCS +0 +byte = $38 // SEC +byte = $CA // DEX +byte = $D0, $18 // BNE +18 +byte = $88 // DEY +byte = $D0, $17 // BNE +17 +byte = $2C, $30, $C0 // BIT $C030 +byte = $A6, $E7 // LDX TMPL +byte = $A4, $E8 // LDY TMPH +byte = $E9, $01 // SBC #$01 +byte = $B0, $EA // BCS -EA +byte = $C6, $08 // DEC DSTL +byte = $D0, $EA // BNE -EA +byte = $C6, $09 // DEC DSTH +byte = $D0, $E6 // BNE -E6 +byte = $F0, $07 // BEQ +8 +byte = $EA // NOP +byte = $EA // NOP +byte = $EA, $EA // BIT $C000 (nope) +byte = $EA // NOP +byte = $D0, $EB // BNE -EA +byte = $28 // PLP +byte = $A6, $E5 // LDX ESP +byte = $E8 // INX +byte = $E8 // INX +byte = $60 // RTS + +def game(spdrcnt)#1 + var[8] xspdr, yspdr, ixspdr, iyspdr, hatch + var xship, xmissle, leftxlaser, rightxlaser, attack + byte[8] life, death + byte lasercharging, missleloading, misslecnt, ymissle + byte leftylaser, rightylaser, lefthit, righthit, sprtnum[], width + byte spdrnum, k, xdelta, ydelta, btn0, btn1, webstate + + xship = 140 + ymissle = 255 // Not active value + misslecnt = 6 + missleloading = FALSE + lasercharging = FALSE + // + // Initialize the spiders (first is special) + // + xspdr[0] = 100 + ixspdr[0] = 1 + yspdr[0] = 60 + iyspdr[0] = -1 + hatch[0] = 1 + life[0] = 3 + death[0] = 0 + attack = -1 + webstate = 0 + // + // Initialize spiders + // + spdrnum = spdrcnt - 1 + for k = 1 to spdrnum + spriteAdd(k + SPIDER_SPRTEBASE, spriteDup(sprtEgg3)) + xspdr[k] = ((xspdr[k - 1] ^ 37) + 97) & 255 + ixspdr[k] = -ixspdr[k - 1] + yspdr[k] = ((yspdr[k - 1] ^ 29) + 53) & 63 + iyspdr[k] = -iyspdr[k - 1] + hatch[k] = k / 2 + 1//hatch[k - 1] + 1 + life[k] = 3 + death[k] = 0 + next + // + // Initialize missle display + // + hgrColor(3) + hgrRect(0, YSHIP+3, 279, 191) + for k = 0 to misslecnt-1 + spritePos(k * 16 + 160, 184, sprtMissle) + spriteDrawXor(sprtMissle) + next + hgrColor(1) + hgrRect(4, YSHIP+6, LASER_RECHARGE * 4 + 4, 188) + // + // Main game loop + // + repeat + // + // Move living spiders + // + for k = 0 to spdrnum + if life[k] + yspdr[k] = yspdr[k] + iyspdr[k] + if yspdr[k] < -5 + // + // Above screen + // + iyspdr[k] = 1 + if hatch[k] + hatch[k]-- + if hatch[k] == 0 + // + // Hatch this egg into a spider + // + life[k] = 3 // Reset life + spriteAdd(k + SPIDER_SPRTEBASE, spriteDup(sprtSpider3)) + fin + fin + fin + if yspdr[k] > SWARM_LIMIT + // + // Attack or not? + // + if hatch[k] == 0 and attack < 0 + attack = k + iyspdr[k] = ATTACK_SPEED + fin + if attack == k + // + // Attacking + // + if yspdr[k] > WEB_LIMIT + // + // Iterate through web sequence + // + when webstate + is 10 + iyspdr[k] = -8 // Retreat + yspdr[k] = WEB_LIMIT + spriteDel(2) + spriteDel(3) + spriteDel(4) + webstate = 0 + break + is 0 + iyspdr[k] = 0 + spriteAdd(2, sprtWeb1) + spritePosIndex(xspdr[k], WEB_LIMIT+7, 2) + buzz = WEB1_BUZZ + webstate = 1 + break + is 1 + spriteAdd(3, sprtWeb2) + spritePosIndex(xspdr[k], WEB_LIMIT+15, 3) + buzz = WEB2_BUZZ + webstate = 2 + break + is 2 + spriteAdd(4, sprtWeb3) + spritePosIndex(xspdr[k], WEB_LIMIT+22, 4) + webstate = 3 + otherwise + // + // States 3..9 just repeat this + // + if xship >= xspdr[k] - 17 and xship <= xspdr[k] + 17 + // + // Capture ship + // + return FALSE + fin + buzz = WEB3_BUZZ + webstate++ + wend + else + if iyspdr[k] > 0 + // + // Move towards player during attack, but not too fast + // + xdelta = yspdr[k] > FASTMOVE_LIMIT ?? 2 :: 4 + xspdr[k] = xspdr[k] + (xship - xspdr[k]) / xdelta + buzz = ATTACK_BUZZ + else + // + // Retreat at a progressively faster rate + // + if ixspdr[k] > 0 + xspdr[k] = xspdr[k] + (WEB_LIMIT - yspdr[k]) / 8 + else + xspdr[k] = xspdr[k] - (WEB_LIMIT - yspdr[k]) / 8 + fin + fin + fin + else + // + // Just reverse direction towards top of screen + // + iyspdr[k] = -1 + fin + else + if attack == k + // + // Retreated back to swarm zone so stop attack + // + attack = -1 + iyspdr[k] = -1 + fin + // + // Swarm movement + // + if ixspdr[k] > 0 + xspdr[k] = xspdr[k] + yspdr[k] / 8 + else + xspdr[k] = xspdr[k] - yspdr[k] / 8 + fin + if xspdr[k] < -5 or xspdr[k] > 284 + if xspdr[k] < -5 + xspdr[k] = -5 + ixspdr[k] = 1 + else + xspdr[k] = 284 + ixspdr[k] = -1 + fin + fin + fin + spritePosIndex(xspdr[k], yspdr[k], k+SPIDER_SPRTEBASE) + elsif death[k] + // + // Splat sequence + // + death[k]-- + if death[k] + spriteAdd(k+SPIDER_SPRTEBASE, spriteDup(sprtSplat2)) + spritePosIndex(xspdr[k], yspdr[k], k+SPIDER_SPRTEBASE) + else + spriteAdd(k+SPIDER_SPRTEBASE, spriteDup(sprtDummy)) + spritePosIndex(0, 0, k+SPIDER_SPRTEBASE) + spdrcnt-- + if not spdrcnt + return TRUE + fin + buzz = SPLAT_BUZZ + fin + fin + next + // + // Move ship + // + xdelta, ydelta, btn0, btn1 = joypos(buzz) + buzz = spdrcnt * 4 + xship = xship + ((xdelta + 4) / 8 - 5) + if xship < 0; xship = 0; fin + if xship > 279; xship = 279; fin + spritePosIndex(xship, YSHIP, SHIP_SPRTNUM) + // + // Missle + // + if misslecnt and missleloading + missleloading-- + fin + if btn1 and not missleloading and ymissle == 255 + // + // Fire missle + // + xmissle = xship + ymissle = YSHIP-15 + missleloading = MISSLE_RELOAD + misslecnt-- + spritePos(misslecnt * 16 + 160, 184, sprtMissle) // Erase from armory + spriteDrawXor(sprtMissle) + spriteAdd(1, sprtMissle) + fin + if ymissle <> 255 + if ymissle < 8 + // + // Missle off top of screen + // + spriteDel(1) + ymissle = 255 + else + ymissle = ymissle - 8 + spritePosIndex(xmissle, ymissle, MISSLE_SPRTNUM) + for k = 0 to spdrnum + if life[k] + // + // Hit test will all living spiders + // + if ymissle >= yspdr[k] - 15 and ymissle <= yspdr[k] + 5 + if hatch[k] + width = 7 // Egg width + else + width = 10 // Spider width + fin + if xmissle >= xspdr[k] - width and xmissle <= xspdr[k] + width + // + // Hit & kill spider + // + life[k] = 0 + death[k] = 2 + spriteAdd(k+SPIDER_SPRTEBASE, spriteDup(sprtSplat1)) + spritePosIndex(xspdr[k], yspdr[k], k+SPIDER_SPRTEBASE) + if attack == k // Was it attacking? + attack = -1 + spriteDel(2) + spriteDel(3) + spriteDel(4) + webstate = 0 + fin + // + // Remove missle + // + spriteDel(MISSLE_SPRTNUM) + ymissle = 255 + fin + fin + fin + next + buzz = ymissle/4 + fin + fin + // + // Update sprites + // + spriteDrawXorList() + // + // Lasers + // + if lasercharging + lasercharging-- + hgrColor(1) + hgrRect(81 - lasercharging*4, YSHIP+6, 84 - lasercharging*4, 188) + fin + if btn0 and not lasercharging + // + // Fire laser + // + hgrColor(0) + hgrRect(4, YSHIP+6, LASER_RECHARGE * 4 + 4, 188) + lasercharging = LASER_RECHARGE + leftxlaser = xship - 7 + rightxlaser = xship + 7 + leftylaser = 0 + rightylaser = 0 + lefthit = 255 + righthit = 255 + for k = 0 to spdrnum + if life[k] + // + // Hit test will all living spiders + // + if hatch[k] + width = 7 // Egg width + else + width = 10 // Spider width + fin + if leftxlaser >= xspdr[k]-width and leftxlaser <= xspdr[k]+width + if yspdr[k] + 5 > leftylaser + lefthit = k + leftylaser = yspdr[k] + 5 + fin + fin + if rightxlaser >= xspdr[k]-width and rightxlaser <= xspdr[k]+width + if yspdr[k] + 5 > rightylaser + righthit = k + rightylaser = yspdr[k] + 5 + fin + fin + fin + next + // + // Draw Laser beams + // + hgrColor(3) + if leftxlaser >= 0 + hgrXorVLin(leftylaser, YSHIP-8, leftxlaser) + hgrXorVLin(leftylaser, YSHIP-8, leftxlaser+1) + fin + if rightxlaser < 280 + hgrXorVLin(rightylaser, YSHIP-8, rightxlaser) + hgrXorVLin(rightylaser, YSHIP-8, rightxlaser-1) + fin + buzz = LASER_BUZZ + (@_spkrTone)(15, 1)#0 + if lefthit <> 255 + sprtnum = lefthit + SPIDER_SPRTEBASE + // + // Hit + // + life[lefthit]-- + if not life[lefthit] + // + // Kill spider + // + death[lefthit] = 2 + spriteAdd(sprtnum, spriteDup(sprtSplat1)) + spritePosIndex(xspdr[lefthit], yspdr[lefthit], sprtnum) + if attack == lefthit // Was it attacking? + spriteDel(2) + spriteDel(3) + spriteDel(4) + webstate = 0 + attack = -1 + fin + else + // + // Dim color to show life status + // + if hatch[lefthit] + sprtEgg = life[lefthit] == 2 ?? sprtEgg2 :: sprtEgg1 + spriteAdd(sprtnum, spriteDup(sprtEgg)) + else + sprtSpider = life[lefthit] == 2 ?? sprtSpider2 :: sprtSpider1 + spriteAdd(sprtnum, spriteDup(sprtSpider)) + fin + spritePosIndex(xspdr[lefthit], yspdr[lefthit], sprtnum) + fin + fin + if righthit <> 255 and life[righthit] + sprtnum = righthit + SPIDER_SPRTEBASE + // + // Hit + // + life[righthit]-- + if not life[righthit] + // + // Kill spider + // + death[righthit] = 2 + spriteAdd(sprtnum, spriteDup(sprtSplat1)) + spritePosIndex(xspdr[righthit], yspdr[righthit], sprtnum) + if attack == righthit // Was it attacking? + spriteDel(2) + spriteDel(3) + spriteDel(4) + webstate = 0 + attack = -1 + fin + else + // + // Dim color to show life status + // + if hatch[righthit] + sprtEgg = life[righthit] == 2 ?? sprtEgg2 :: sprtEgg1 + spriteAdd(sprtnum, spriteDup(sprtEgg)) + else + sprtSpider = life[righthit] == 2 ?? sprtSpider2 :: sprtSpider1 + spriteAdd(sprtnum, spriteDup(sprtSpider)) + fin + spritePosIndex(xspdr[righthit], yspdr[righthit], sprtnum) + fin + fin + // + // Undraw lasers + // + hgrColor(3) + if leftxlaser >= 0 + hgrXorVLin(leftylaser, YSHIP-8, leftxlaser) + hgrXorVLin(leftylaser, YSHIP-8, leftxlaser+1) + fin + if rightxlaser < 280 + hgrXorVLin(rightylaser, YSHIP-8, rightxlaser) + hgrXorVLin(rightylaser, YSHIP-8, rightxlaser-1) + fin + fin + // + // Update stars + // + hgrColor(3) + hgrXorPlot(xstar[curstar], ystar[curstar]) + ystar[curstar]++ + if ystar[curstar] > YSHIP + ystar[curstar] = 0 + fin + hgrXorPlot(xstar[curstar], ystar[curstar]) + curstar++ + if curstar >= NUMSTARS; curstar = 0; fin + until ^$C000 == $9B // ESCape key pressed + getc + return FALSE +end +// +// Initialization +// +puts("Loading"); +putc('.') +sprtShip = spriteRead("SHIP") +if not sprtShip + cmdsys:modexec("SFMSPRT") + sprtShip = spriteRead("SHIP") + if not sprtShip + puts("\nError: Unable to compile sprites.\n") + return -1 + fin +fin +putc('.') +sprtMissle = spriteRead("MISSLE") +putc('.') +sprtEgg3 = spriteRead("EGG3") +putc('.') +sprtEgg2 = spriteRead("EGG2") +putc('.') +sprtEgg1 = spriteRead("EGG1") +putc('.') +sprtSpider3= spriteRead("SPIDER3") +putc('.') +sprtSpider2= spriteRead("SPIDER2") +putc('.') +sprtSpider1= spriteRead("SPIDER1") +putc('.') +sprtWeb1 = spriteRead("WEB1") +putc('.') +sprtWeb2 = spriteRead("WEB2") +putc('.') +sprtWeb3 = spriteRead("WEB3") +putc('.') +sprtSplat1 = spriteRead("SPLAT1") +putc('.') +sprtSplat2 = spriteRead("SPLAT2") +putc('.') +sprtDummy = spriteRead("DUMMY") +// +// Heat up JIT compiler +// +for curstar = 0 to 50 + putc('.') + spriteAdd(0, sprtDummy) + spritePosIndex(0, 0, 0) + spriteDrawXorList() +next +heapstart = heapmark() +//puts("\nBeginning available memory: "); puti(heapavail()); putln +repeat + hgrMode(TRUE) + spriteDrawBuf(hgrDrawBuf(0)) // Single buffered + spriteAdd(SHIP_SPRTNUM, sprtShip) + spriteAdd(SPIDER_SPRTEBASE, sprtEgg3) + // + // Init stars + // + xstar[0] = 99 + ystar[0] = 10 + hgrColor(3) + hgrXorPlot(xstar[0], ystar[0]) + for curstar = 1 to NUMSTARS-1 + xstar[curstar] = (xstar[curstar - 1] + 97 - curstar) % 280 + ystar[curstar] = (ystar[curstar - 1] + 19 + curstar) % YSHIP + hgrXorPlot(xstar[curstar], ystar[curstar]) + next + curstar = 0 + if game(8) + // + // Won + // + spriteDrawXorList() + (@_spkrTone)(100, 20)#0 + (@_spkrTone)(75, 20)#0 + (@_spkrTone)(15, 20)#0 + (@_spkrTone)(25, 100)#0 + puts("\nZiggy Stardust has saved Earth!\n") + else + // + // Lost + // + spriteDrawXorList() + (@_spkrTone)(100, 50)#0 + spriteDrawXor(sprtShip) + (@_spkrTone)(150, 50)#0 + spriteDrawXor(sprtShip) + (@_spkrTone)(100, 50)#0 + spriteDrawXor(sprtShip) + (@_spkrTone)(150, 50)#0 + puts("\nEarth has been overrun") + puts("\nby the Spiders from Mars\n") + fin + hgrMode(FALSE) + // + // Clear sprite lists + // + for curstar = 0 to 15 + spriteDel(curstar) + next + spriteDrawXorList() + spriteDrawXorList() + // + // Reset heap + // + heaprelease(heapstart) + //puts("\nAvailable memory: "); puti(heapavail()); putln + puts("Play again (Y/N)?") +until toupper(getc) <> 'Y' +putln +done diff --git a/src/samplesrc/sfmsprt.pla b/src/samplesrc/sfmsprt.pla new file mode 100644 index 0000000..6f53a34 --- /dev/null +++ b/src/samplesrc/sfmsprt.pla @@ -0,0 +1,203 @@ +include "inc/cmdsys.plh" +include "inc/hgrlib.plh" +include "inc/hgrsprite.plh" +sysflags reshgr1 // Reserve HGR page 1 + + +byte egg3 = $88,$88,$83,$33,$38,$88,$88 +byte = $88,$83,$33,$11,$33,$38,$88 +byte = $83,$31,$11,$11,$11,$13,$38 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $33,$11,$11,$11,$11,$11,$33 +byte = $83,$31,$11,$11,$11,$13,$38 +byte = $88,$83,$33,$11,$33,$38,$88 +byte = $88,$88,$83,$33,$38,$88,$88 +byte egg2 = $88,$88,$83,$33,$38,$88,$88 +byte = $88,$83,$33,$11,$33,$38,$88 +byte = $83,$30,$11,$00,$11,$13,$38 +byte = $33,$11,$00,$11,$00,$11,$33 +byte = $33,$00,$11,$00,$11,$00,$33 +byte = $33,$11,$00,$11,$00,$11,$33 +byte = $33,$00,$11,$00,$11,$00,$33 +byte = $33,$11,$00,$11,$00,$11,$33 +byte = $33,$00,$11,$00,$11,$00,$33 +byte = $83,$31,$00,$11,$00,$13,$38 +byte = $88,$83,$33,$00,$33,$38,$88 +byte = $88,$88,$83,$33,$38,$88,$88 +byte egg1 = $88,$88,$83,$33,$38,$88,$88 +byte = $88,$83,$33,$00,$33,$38,$88 +byte = $83,$30,$00,$00,$00,$03,$38 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $33,$00,$00,$00,$00,$00,$33 +byte = $83,$30,$00,$00,$00,$03,$38 +byte = $88,$83,$33,$11,$33,$38,$88 +byte = $88,$88,$83,$33,$38,$88,$88 +byte spider3 = $33,$88,$88,$33,$33,$33,$33,$88,$88,$33 +byte = $33,$88,$83,$32,$22,$22,$23,$38,$88,$33 +byte = $83,$38,$83,$32,$22,$22,$23,$38,$83,$38 +byte = $88,$83,$33,$22,$22,$22,$22,$33,$38,$88 +byte = $33,$88,$33,$22,$22,$22,$22,$33,$88,$33 +byte = $88,$33,$38,$33,$22,$22,$33,$83,$33,$88 +byte = $88,$88,$83,$33,$22,$22,$33,$38,$88,$88 +byte = $88,$33,$33,$33,$22,$22,$33,$33,$33,$88 +byte = $33,$88,$88,$88,$33,$33,$88,$88,$88,$33 +byte = $88,$88,$33,$33,$22,$22,$33,$33,$88,$88 +byte = $88,$33,$88,$33,$22,$22,$33,$88,$33,$88 +byte = $33,$88,$88,$83,$32,$23,$38,$88,$88,$33 +byte = $88,$88,$88,$88,$33,$33,$88,$88,$88,$88 +byte spider2 = $33,$88,$88,$33,$33,$33,$33,$88,$88,$33 +byte = $33,$88,$83,$30,$02,$20,$03,$38,$88,$33 +byte = $83,$38,$83,$32,$20,$02,$23,$38,$83,$38 +byte = $88,$83,$33,$20,$02,$20,$02,$33,$38,$88 +byte = $33,$88,$33,$02,$20,$02,$20,$33,$88,$33 +byte = $88,$33,$38,$30,$02,$20,$03,$83,$33,$88 +byte = $88,$88,$83,$33,$20,$02,$33,$38,$88,$88 +byte = $88,$33,$33,$30,$02,$20,$03,$33,$33,$88 +byte = $33,$88,$88,$88,$33,$33,$88,$88,$88,$33 +byte = $88,$88,$33,$30,$02,$20,$03,$33,$88,$88 +byte = $88,$33,$88,$33,$20,$02,$33,$88,$33,$88 +byte = $33,$88,$88,$83,$32,$23,$38,$88,$88,$33 +byte = $88,$88,$88,$88,$33,$33,$88,$88,$88,$88 +byte spider1 = $33,$88,$88,$33,$33,$33,$33,$88,$88,$33 +byte = $33,$88,$83,$30,$00,$00,$03,$38,$88,$33 +byte = $83,$38,$83,$30,$00,$00,$03,$38,$83,$38 +byte = $88,$83,$33,$00,$00,$00,$00,$33,$38,$88 +byte = $33,$88,$33,$00,$00,$00,$00,$33,$88,$33 +byte = $88,$33,$38,$33,$00,$00,$33,$83,$33,$88 +byte = $88,$88,$83,$33,$00,$00,$33,$38,$88,$88 +byte = $88,$33,$33,$30,$00,$00,$03,$33,$33,$88 +byte = $33,$88,$88,$88,$33,$33,$88,$88,$88,$33 +byte = $88,$88,$33,$30,$00,$00,$03,$33,$88,$88 +byte = $88,$33,$88,$33,$00,$00,$33,$88,$33,$88 +byte = $33,$88,$88,$83,$30,$03,$38,$88,$88,$33 +byte = $88,$88,$88,$88,$33,$33,$88,$88,$88,$88 +byte web1 = $88,$83,$38,$88 +byte = $88,$38,$83,$88 +byte = $88,$38,$83,$88 +byte = $88,$33,$33,$88 +byte = $83,$38,$83,$38 +byte = $83,$38,$83,$38 +byte = $83,$38,$83,$38 +byte = $33,$33,$33,$33 +byte web2 = $88,$33,$83,$38,$33,$88 +byte = $88,$38,$83,$38,$83,$88 +byte = $83,$38,$83,$38,$83,$38 +byte = $83,$33,$33,$33,$33,$38 +byte = $83,$38,$83,$38,$83,$38 +byte = $83,$38,$83,$38,$83,$38 +byte = $33,$88,$83,$38,$88,$33 +byte = $33,$33,$33,$33,$33,$33 +byte web3 = $88,$83,$38,$83,$38,$83,$38,$83,$38,$88 +byte = $88,$83,$38,$83,$38,$83,$38,$83,$38,$88 +byte = $88,$33,$88,$33,$88,$88,$33,$88,$33,$88 +byte = $88,$33,$33,$33,$33,$33,$33,$33,$33,$88 +byte = $83,$38,$88,$33,$83,$38,$33,$88,$83,$38 +byte = $83,$38,$83,$38,$83,$38,$83,$38,$83,$38 +byte = $33,$88,$83,$38,$83,$38,$83,$38,$88,$33 +byte = $33,$38,$33,$33,$33,$33,$33,$33,$33,$33 +byte splat1 = $88,$88,$88,$22,$22,$22,$22,$88,$88,$88 +byte = $88,$88,$88,$22,$11,$11,$22,$88,$88,$88 +byte = $88,$88,$88,$22,$11,$11,$22,$88,$88,$88 +byte = $88,$82,$22,$11,$11,$11,$11,$22,$28,$88 +byte = $22,$22,$22,$11,$11,$11,$11,$22,$22,$22 +byte = $88,$22,$28,$22,$11,$11,$22,$82,$22,$88 +byte = $88,$88,$82,$22,$11,$11,$22,$28,$88,$88 +byte = $88,$22,$22,$22,$11,$11,$22,$22,$22,$88 +byte = $22,$22,$88,$88,$22,$22,$88,$88,$22,$22 +byte = $88,$88,$22,$22,$11,$11,$22,$22,$88,$88 +byte = $88,$22,$22,$22,$11,$11,$22,$22,$22,$88 +byte = $22,$22,$88,$82,$21,$12,$28,$88,$22,$22 +byte = $88,$88,$88,$88,$22,$22,$88,$88,$88,$88 +byte splat2 = $88,$88,$88,$88,$22,$22,$22,$22,$88,$88,$88,$88 +byte = $88,$88,$88,$88,$22,$11,$11,$22,$88,$88,$88,$88 +byte = $88,$88,$88,$82,$22,$11,$11,$22,$88,$88,$88,$88 +byte = $88,$88,$88,$22,$11,$11,$11,$11,$22,$88,$88,$88 +byte = $88,$88,$82,$22,$11,$18,$81,$11,$22,$28,$88,$88 +byte = $88,$22,$22,$22,$11,$88,$88,$11,$22,$22,$22,$88 +byte = $22,$28,$82,$22,$11,$88,$88,$11,$22,$28,$82,$22 +byte = $88,$88,$22,$28,$88,$88,$88,$88,$82,$22,$88,$88 +byte = $88,$88,$88,$22,$88,$88,$88,$11,$22,$88,$88,$88 +byte = $88,$88,$22,$22,$11,$88,$88,$11,$22,$22,$88,$88 +byte = $88,$22,$22,$22,$11,$18,$81,$11,$22,$22,$22,$88 +byte = $88,$88,$88,$22,$11,$18,$81,$11,$22,$88,$88,$88 +byte = $88,$88,$22,$22,$11,$11,$11,$11,$22,$22,$88,$88 +byte = $88,$22,$22,$88,$22,$11,$11,$22,$88,$22,$22,$88 +byte = $22,$28,$88,$88,$88,$22,$22,$88,$88,$88,$82,$22 +byte = $88,$88,$22,$22,$22,$11,$11,$22,$22,$22,$88,$88 +byte = $88,$88,$22,$28,$22,$11,$11,$22,$82,$22,$88,$88 +byte ship = $CC,$CC,$CC,$77,$CC,$CC,$CC +byte = $CC,$CC,$C7,$77,$7C,$CC,$CC +byte = $CC,$CC,$C7,$77,$7C,$CC,$CC +byte = $CC,$CC,$C7,$77,$7C,$CC,$CC +byte = $CC,$CC,$C7,$77,$7C,$CC,$CC +byte = $77,$CC,$77,$66,$77,$CC,$77 +byte = $77,$CC,$77,$66,$77,$CC,$77 +byte = $77,$CC,$77,$66,$77,$CC,$77 +byte = $77,$CC,$77,$77,$77,$CC,$77 +byte = $77,$CC,$77,$77,$77,$CC,$77 +byte = $77,$CC,$77,$77,$77,$CC,$77 +byte = $77,$C7,$77,$77,$77,$7C,$77 +byte = $77,$77,$75,$55,$57,$77,$77 +byte = $77,$77,$75,$55,$57,$77,$77 +byte missle = $CC,$55,$CC +byte = $CC,$55,$CC +byte = $CC,$55,$CC +byte = $CC,$55,$CC +byte = $CC,$55,$CC +byte = $CC,$55,$CC +byte = $C5,$55,$5C +byte = $55,$55,$55 +byte dummy = $88,$88,$88,$88 +byte = $88,$88,$88,$88 +byte = $88,$88,$88,$88 +byte = $88,$88,$88,$88 +byte = $88,$88,$88,$88 +byte = $88,$88,$88,$88 +byte = $88,$88,$88,$88 +byte = $88,$88,$88,$88 +var sprtEgg1, sprtEgg2, sprtEgg3 +var sprtSpider1, sprtSpider2, sprtSpider3 +var sprtSplat1, sprtSplat2 +var sprtWeb1, sprtWeb2, sprtWeb3 +var sprtShip, sprtMissle, sprtDummy + +hgrMode(TRUE) +spriteDrawBuf(hgrDrawBuf(0)) // So we can see the compile process +sprtShip = spriteCompile(14, 14, 7, 13, @ship) +sprtMissle = spriteCompile( 6, 8, 3, 0, @missle) +sprtEgg3 = spriteCompile(14, 12, 7, 6, @egg3) +sprtEgg2 = spriteCompile(14, 12, 7, 6, @egg2) +sprtEgg1 = spriteCompile(14, 12, 7, 6, @egg1) +sprtSpider3= spriteCompile(20, 13, 10, 6, @spider3) +sprtSpider2= spriteCompile(20, 13, 10, 6, @spider2) +sprtSpider1= spriteCompile(20, 13, 10, 6, @spider1) +sprtWeb1 = spriteCompile( 8, 8, 4, 0, @web1) +sprtWeb2 = spriteCompile(12, 8, 6, 0, @web2) +sprtWeb3 = spriteCompile(20, 8, 10, 0, @web3) +sprtSplat1 = spriteCompile(20, 13, 10, 6, @splat1) +sprtSplat2 = spriteCompile(24, 17, 12, 8, @splat2) +sprtDummy = spriteCompile( 7, 8, 0, 0, @dummy) +hgrMode(FALSE) +spriteSave("SHIP", sprtShip) +spriteSave("MISSLE", sprtMissle) +spriteSave("EGG3", sprtEgg3) +spriteSave("EGG2", sprtEgg2) +spriteSave("EGG1", sprtEgg1) +spriteSave("SPIDER1", sprtSpider1) +spriteSave("SPIDER2", sprtSpider2) +spriteSave("SPIDER3", sprtSpider3) +spriteSave("WEB1", sprtWeb1) +spriteSave("WEB2", sprtWeb2) +spriteSave("WEB3", sprtWeb3) +spriteSave("SPLAT1", sprtSplat1) +spriteSave("SPLAT2", sprtSplat2) +spriteSave("DUMMY", sprtDummy) +done diff --git a/src/samplesrc/test.pla b/src/samplesrc/test.pla index a8a1c26..73a29eb 100755 --- a/src/samplesrc/test.pla +++ b/src/samplesrc/test.pla @@ -204,5 +204,9 @@ puti(array:0); puts(" > "); puti(array:0); puts (" is ") puts(array:0 > array:0 ?? "TRUE\n" :: "FALSE\n") puti(array:0); puts(" < "); puti(array:0); puts (" is ") puts(array:0 < array:0 ?? "TRUE\n" :: "FALSE\n") -ptr = 0 +ptr = 5 +puts("5*0="); puti(ptr*0); putln +puts("5*1="); puti(ptr*1); putln +puts("5*2="); puti(ptr*2); putln +puts("5/1="); puti(ptr/1); putln done diff --git a/src/samplesrc/tiletest.pla b/src/samplesrc/tiletest.pla new file mode 100644 index 0000000..0e4ff28 --- /dev/null +++ b/src/samplesrc/tiletest.pla @@ -0,0 +1,13 @@ +include "inc/cmdsys.plh" +include "inc/hgrtile.plh" +include "inc/hgrfont.plh" +sysflags reshgr1 // Reserve HGR page 1 + +tileMode(TRUE) +hgrPutStr(5, 1, "Hello HiRes Tile Demo") +getc +tileFromText(0, @hgrFont) +getc +tileMode(FALSE) +done + diff --git a/src/tftpbld b/src/tftpbld index 4acd1b0..8e6fe23 100755 --- a/src/tftpbld +++ b/src/tftpbld @@ -6,11 +6,19 @@ echo "BLD/CODEOPT"; atftp $1 --put -l rel/CODEOPT#FE1000 -r $2/BLD/CODEOPT#FE10 #Build incs echo "BLD/INC/ARGS.PLH"; atftp $1 --put -l inc/args.plh -r $2/BLD/INC/ARGS.PLH#040000 +echo "BLD/INC/MATCHFILES.PLH"; atftp $1 --put -l inc/matchfiles.plh -r $2/BLD/INC/MATCHFILES.PLH#040000 echo "BLD/INC/CMDSYS.PLH"; atftp $1 --put -l inc/cmdsys.plh -r $2/BLD/INC/CMDSYS.PLH#040000 echo "BLD/INC/CONIO.PLH"; atftp $1 --put -l inc/conio.plh -r $2/BLD/INC/CONIO.PLH#040000 -echo "BLD/INC/DGR.PLH"; atftp $1 --put -l inc/dgr.plh -r $2/BLD/INC/DGR.PLH#040000 +echo "BLD/INC/LINES.PLH"; atftp $1 --put -l inc/lines.plh -r $2/BLD/INC/LINES.PLH#040000 +echo "BLD/INC/HGRTILE.PLH"; atftp $1 --put -l inc/hgrtile.plh -r $2/BLD/INC/HGRTILE.PLH#040000 +echo "BLD/INC/HGRFONT.PLH";atftp $1 --put -l inc/hgrfont.plh -r $2/BLD/INC/HGRFONT.PLH#040000 +echo "BLD/INC/HGRSPRITE.PLH";atftp $1 --put -l inc/hgrsprite.plh -r $2/BLD/INC/HGRSPRITE.PLH#040000 +echo "BLD/INC/HGRLIB.PLH"; atftp $1 --put -l inc/hgrlib.plh -r $2/BLD/INC/HGRLIB.PLH#040000 +echo "BLD/INC/GRLIB.PLH"; atftp $1 --put -l inc/grlib.plh -r $2/BLD/INC/GRLIB.PLH#040000 +echo "BLD/INC/DGRLIB.PLH"; atftp $1 --put -l inc/dgrlib.plh -r $2/BLD/INC/DGRLIB.PLH#040000 echo "BLD/INC/FIBER.PLH"; atftp $1 --put -l inc/fiber.plh -r $2/BLD/INC/FIBER.PLH#040000 echo "BLD/INC/FILEIO.PLH"; atftp $1 --put -l inc/fileio.plh -r $2/BLD/INC/FILEIO.PLH#040000 +echo "BLD/INC/INT32.PLH"; atftp $1 --put -l inc/int32.plh -r $2/BLD/INC/INT32.PLH#040000 echo "BLD/INC/FPSTR.PLH"; atftp $1 --put -l inc/fpstr.plh -r $2/BLD/INC/FPSTR.PLH#040000 echo "BLD/INC/FPU.PLH"; atftp $1 --put -l inc/fpu.plh -r $2/BLD/INC/FPU.PLH#040000 echo "BLD/INC/GRAFIX.PLH"; atftp $1 --put -l inc/grafix.plh -r $2/BLD/INC/GRAFIX.PLH#040000 @@ -27,7 +35,27 @@ echo "BLD/INC/SNDSEQ.PLH"; atftp $1 --put -l inc/sndseq.plh -r $2/BLD/INC/SND echo "BLD/INC/SPIPORT.PLH"; atftp $1 --put -l inc/spiport.plh -r $2/BLD/INC/SPIPORT.PLH#040000 echo "BLD/INC/TESTLIB.PLH"; atftp $1 --put -l inc/testlib.plh -r $2/BLD/INC/TESTLIB.PLH#040000 -# Sample source -echo "BLD/MOUSETEST.PLA"; atftp $1 --put -l samplesrc/mousetest.pla -r $2/BLD/MOUSETEST.PLA#040000 -echo "BLD/HTTPD.PLA"; atftp $1 --put -l samplesrc/httpd.pla -r $2/BLD/HTTPD.PLA#040000 -echo "BLD/LZ4CAT.PLA"; atftp $1 --put -l samplesrc/lz4cat.pla -r $2/BLD/LZ4CAT.PLA#040000 +# Sample sources +echo "BLD/SAMPLES/HELLO.PLA"; atftp $1 --put -l samplesrc/hello.pla -r $2/BLD/SAMPLES/HELLO.PLA#040000 +echo "BLD/SAMPLES/TESTLIB.PLA"; atftp $1 --put -l samplesrc/testlib.pla -r $2/BLD/SAMPLES/TESTLIB.PLA#040000 +echo "BLD/SAMPLES/TEST.PLA"; atftp $1 --put -l samplesrc/test.pla -r $2/BLD/SAMPLES/TEST.PLA#040000 +echo "BLD/SAMPLES/FIBERTEST.PLA"; atftp $1 --put -l samplesrc/fibertest.pla -r $2/BLD/SAMPLES/FIBERTEST.PLA#040000 +echo "BLD/SAMPLES/MOUSETEST.PLA"; atftp $1 --put -l samplesrc/mousetest.pla -r $2/BLD/SAMPLES/MOUSETEST.PLA#040000 +echo "BLD/SAMPLES/ROD.PLA"; atftp $1 --put -l samplesrc/rod.pla -r $2/BLD/SAMPLES/ROD.PLA#040000 +echo "BLD/SAMPLES/INT32TEST.PLA"; atftp $1 --put -l samplesrc/int32test.pla -r $2/BLD/SAMPLES/INT32TEST.PLA#040000 +echo "BLD/SAMPLES/HGRTEST.PLA"; atftp $1 --put -l samplesrc/hgrtest.pla -r $2/BLD/SAMPLES/HGRTEST.PLA#040000 +echo "BLD/SAMPLES/GRTEST.PLA"; atftp $1 --put -l samplesrc/grtest.pla -r $2/BLD/SAMPLES/GRTEST.PLA#040000 +echo "BLD/SAMPLES/DGRTEST.PLA"; atftp $1 --put -l samplesrc/dgrtest.pla -r $2/BLD/SAMPLES/DGRTEST.PLA#040000 +echo "BLD/SAMPLES/TILETEST.PLA"; atftp $1 --put -l samplesrc/tiletest.pla -r $2/BLD/SAMPLES/TILETEST.PLA#040000 +echo "BLD/SAMPLES/HGRTEST.PLA"; atftp $1 --put -l samplesrc/hgrtest.pla -r $2/BLD/SAMPLES/HGRTEST.PLA#040000 +echo "BLD/SAMPLES/PLAYSEQ.PLA"; atftp $1 --put -l samplesrc/playseq.pla -r $2/BLD/SAMPLES/PLAYSEQ.PLA#040000 +echo "BLD/SAMPLES/RPNCALC.PLA"; atftp $1 --put -l samplesrc/rpncalc.pla -r $2/BLD/SAMPLES/RPNCALC.PLA#040000 +echo "BLD/SAMPLES/SIEVE.PLA"; atftp $1 --put -l samplesrc/sieve.pla -r $2/BLD/SAMPLES/SIEVE.PLA#040000 +echo "BLD/SAMPLES/MEMTEST.PLA"; atftp $1 --put -l samplesrc/memtest.pla -r $2/BLD/SAMPLES/MEMTEST.PLA#040000 +echo "BLD/SAMPLES/FATCAT.PLA"; atftp $1 --put -l samplesrc/fatcat.pla -r $2/BLD/SAMPLES/FATCAT.PLA#040000 +echo "BLD/SAMPLES/GFXDEMO.PLA"; atftp $1 --put -l samplesrc/gfxdemo.pla -r $2/BLD/SAMPLES/GFXDEMO.PLA#040000 +echo "BLD/SAMPLES/LZ4CAT.PLA"; atftp $1 --put -l samplesrc/lz4cat.pla -r $2/BLD/SAMPLES/LZ4CAT.PLA#040000 +echo "BLD/SAMPLES/SFM.PLA"; atftp $1 --put -l samplesrc/sfm.pla -r $2/BLD/SAMPLES/SFM.PLA#040000 +echo "BLD/SAMPLES/SFMSPRT.PLA"; atftp $1 --put -l samplesrc/sfmsprt.pla -r $2/BLD/SAMPLES/SFMSPRT.PLA#040000 +echo "BLD/SAMPLES/MON.PLA"; atftp $1 --put -l utilsrc/apple/mon.pla -r $2/BLD/SAMPLES/MON.PLA#040000 + diff --git a/src/tftpdemos b/src/tftpdemos index c6fe200..9dcccf8 100755 --- a/src/tftpdemos +++ b/src/tftpdemos @@ -1,4 +1,40 @@ #!/bin/bash +# Demos +echo "DEMOS/RPNCALC"; atftp $1 --put -l rel/RPNCALC#FE1000 -r $2/DEMOS/RPNCALC#FE1000 +echo "DEMOS/LZ4CAT"; atftp $1 --put -l rel/LZ4CAT#FE1000 -r $2/DEMOS/LZ4CAT#FE1000 +echo "DEMOS/SIEVE"; atftp $1 --put -l rel/SIEVE#FE1000 -r $2/DEMOS/SIEVE#FE1000 +echo "DEMOS/ROD"; atftp $1 --put -l rel/apple/ROD#FE1000 -r $2/DEMOS/ROD#FE1000 +echo "DEMOS/TILETEST"; atftp $1 --put -l rel/apple/TILETEST#FE1000 -r $2/DEMOS/TILETEST#FE1000 +echo "DEMOS/HGRTEST"; atftp $1 --put -l rel/apple/HGRTEST#FE1000 -r $2/DEMOS/HGRTEST#FE1000 +echo "DEMOS/GRTEST"; atftp $1 --put -l rel/apple/GRTEST#FE1000 -r $2/DEMOS/GRTEST#FE1000 +echo "DEMOS/INT32TEST"; atftp $1 --put -l rel/INT32TEST#FE1000 -r $2/DEMOS/INT32TEST#FE1000 +echo "DEMOS/DGRTEST"; atftp $1 --put -l rel/apple/DGRTEST#FE1000 -r $2/DEMOS/DGRTEST#FE1000 + +# Spiders from Mars +echo "DEMOS/SPIDERS/SFM"; atftp $1 --put -l rel/apple/SFM#FE1000 -r $2/DEMOS/SPIDERS/SFM#FE1000 +echo "DEMOS/SPIDERS/SFMSPRT"; atftp $1 --put -l rel/apple/SFMSPRT#FE1000 -r $2/DEMOS/SPIDERS/SFMSPRT#FE1000 + +# Music demo +echo "DEMOS/MUSIC/PLAYSEQ"; atftp $1 --put -l rel/apple/PLAYSEQ#FE1000 -r $2/DEMOS/MUSIC/PLAYSEQ#FE1000 + atftp $1 --put -l mockingboard/ultima3.seq -r $2/DEMOS/MUSIC/ULTIMA3.SEQ#060000 + atftp $1 --put -l mockingboard/startrek.seq -r $2/DEMOS/MUSIC/STARTREK.SEQ#060000 +# Rogue demo +echo "DEMOS/ROGUE/ROGUE"; atftp $1 --put -l rel/ROGUE#FE1000 -r $2/DEMOS/ROGUE/ROGUE#FE1000 +echo "DEMOS/ROGUE/ROGUEMAP"; atftp $1 --put -l rel/ROGUEMAP#FE1000 -r $2/DEMOS/ROGUE/ROGUEMAP#FE1000 +echo "DEMOS/ROGUE/ROGUECOMBAT"; atftp $1 --put -l rel/ROGUECOMBAT#FE1000 -r $2/DEMOS/ROGUE/ROGUECOMBAT#FE1000 + atftp $1 --put -l samplesrc/LEVEL0#040000 -r $2/DEMOS/ROGUE/LEVEL0#040000 + atftp $1 --put -l samplesrc/LEVEL1#040000 -r $2/DEMOS/ROGUE/LEVEL1#040000 + +# Arduino+SD card demos +echo "DEMOS/SDUTILS/SPIPORT"; atftp $1 --put -l rel/apple/SPIPORT#FE1000 -r $2/DEMOS/SDUTILS/SPIPORT#FE1000 +echo "DEMOS/SDUTILS/SDFAT"; atftp $1 --put -l rel/apple/SDFAT#FE1000 -r $2/DEMOS/SDUTILS/SDFAT#FE1000 +echo "DEMOS/SDUTILS/FATCAT"; atftp $1 --put -l rel/apple/FATCAT#FE1000 -r $2/DEMOS/SDUTILS/FATCAT#FE1000 +echo "DEMOS/SDUTILS/FATGET"; atftp $1 --put -l rel/apple/FATGET#FE1000 -r $2/DEMOS/SDUTILS/FATGET#FE1000 +echo "DEMOS/SDUTILS/FATPUT"; atftp $1 --put -l rel/apple/FATPUT#FE1000 -r $2/DEMOS/SDUTILS/FATPUT#FE1000 +echo "DEMOS/SDUTILS/FATREADDSK"; atftp $1 --put -l rel/apple/FATREADDSK#FE1000 -r $2/DEMOS/SDUTILS/FATREADDSK#FE1000 +echo "DEMOS/SDUTILS/FATWRITEDSK"; atftp $1 --put -l rel/apple/FATWRITEDSK#FE1000 -r $2/DEMOS/SDUTILS/FATWRITEDSK#FE1000 + # Net demos -echo "NET/TFTPD"; atftp $1 --put -l rel/TFTPD#FE1000 -r $2/DEMOS/NET/TFTPD#FE1000 +echo "DEMOS/NET/HTTPD"; atftp $1 --put -l rel/HTTPD#FE1000 -r $2/DEMOS/NET/HTTPD#FE1000 + atftp $1 --put -l samplesrc/index.html -r $2/DEMOS/NET/INDEX.HTML#040000 diff --git a/src/tftprel b/src/tftprel new file mode 100755 index 0000000..2d20b6e --- /dev/null +++ b/src/tftprel @@ -0,0 +1,7 @@ +#!/bin/bash + +./tftpsys $1 $2 +./tftputil $1 $2 +./tftpsane $1 $2 +./tftpbld $1 $2 +./tftpdemos $1 $2 diff --git a/src/tftpsane b/src/tftpsane new file mode 100755 index 0000000..d60dbd9 --- /dev/null +++ b/src/tftpsane @@ -0,0 +1,8 @@ +#!/bin/bash + +# SANE libraries +echo "SYS/SANE"; atftp $1 --put -l rel/SANE#FE1000 -r $2/SYS/SANE#FE1000 +echo "SYS/FPSTR"; atftp $1 --put -l rel/FPSTR#FE1000 -r $2/SYS/FPSTR#FE1000 +echo "SYS/FPU"; atftp $1 --put -l rel/FPU#FE1000 -r $2/SYS/FPU#FE1000 +echo "SYS/FP6502.CODE"; atftp $1 --put -l ../sysfiles/FP6502.CODE#060000 -r $2/SYS/FP6502.CODE#060000 +echo "SYS/ELEMS.CODE"; atftp $1 --put -l ../sysfiles/ELEMS.CODE#060000 -r $2/SYS/ELEMS.CODE#060000 diff --git a/src/tftpsys b/src/tftpsys index e4db851..2b36848 100755 --- a/src/tftpsys +++ b/src/tftpsys @@ -11,26 +11,28 @@ echo "SYS/JIT16"; atftp $1 --put -l rel/apple/JIT16#FE1000 -r $2/SYS/JIT16#F echo "SYS/JITUNE"; atftp $1 --put -l rel/apple/JITUNE#FE1000 -r $2/SYS/JITUNE#FE1000 # Core libraries +echo "SYS/MATCHFILES"; atftp $1 --put -l rel/apple/MATCHFILES#FE1000 -r $2/SYS/MATCHFILES#FE1000 echo "SYS/ARGS"; atftp $1 --put -l rel/ARGS#FE1000 -r $2/SYS/ARGS#FE1000 +echo "SYS/INT32"; atftp $1 --put -l rel/INT32#FE1000 -r $2/SYS/INT32#FE1000 echo "SYS/DHCP"; atftp $1 --put -l rel/DHCP#FE1000 -r $2/SYS/DHCP#FE1000 -echo "SYS/ED"; atftp $1 --put -l rel/ED#FE1000 -r $2/SYS/ED#FE1000 echo "SYS/ETHERIP"; atftp $1 --put -l rel/ETHERIP#FE1000 -r $2/SYS/ETHERIP#FE1000 echo "SYS/MOUSE"; atftp $1 --put -l rel/apple/MOUSE#FE1000 -r $2/SYS/MOUSE#FE1000 echo "SYS/FIBER"; atftp $1 --put -l rel/FIBER#FE1000 -r $2/SYS/FIBER#FE1000 -echo "SYS/FPSTR"; atftp $1 --put -l rel/FPSTR#FE1000 -r $2/SYS/FPSTR#FE1000 -echo "SYS/FPU"; atftp $1 --put -l rel/FPU#FE1000 -r $2/SYS/FPU#FE1000 echo "SYS/INET"; atftp $1 --put -l rel/INET#FE1000 -r $2/SYS/INET#FE1000 echo "SYS/LONGJUMP"; atftp $1 --put -l rel/LONGJMP#FE1000 -r $2/SYS/LONGJMP#FE1000 -echo "SYS/LZ4"; atftp $1 --put -l rel/LZ4#FE1000 -r $2/SYS/LZ4#FE1000 echo "SYS/MEMMGR"; atftp $1 --put -l rel/MEMMGR#FE1000 -r $2/SYS/MEMMGR#FE1000 -echo "SYS/SANE"; atftp $1 --put -l rel/SANE#FE1000 -r $2/SYS/SANE#FE1000 +echo "SYS/LZ4"; atftp $1 --put -l rel/LZ4#FE1000 -r $2/SYS/LZ4#FE1000 echo "SYS/CONIO"; atftp $1 --put -l rel/apple/CONIO#FE1000 -r $2/SYS/CONIO#FE1000 -echo "SYS/DGR"; atftp $1 --put -l rel/apple/DGR#FE1000 -r $2/SYS/DGR#FE1000 +echo "SYS/HGRTILE"; atftp $1 --put -l rel/apple/HGRTILE#FE1000 -r $2/SYS/HGRTILE#FE1000 +echo "SYS/HGRFONT"; atftp $1 --put -l rel/apple/HGRFONT#FE1000 -r $2/SYS/HGRFONT#FE1000 +echo "SYS/HGRSPRITE"; atftp $1 --put -l rel/apple/HGRSPRITE#FE1000 -r $2/SYS/HGRSPRITE#FE1000 +echo "SYS/LINES"; atftp $1 --put -l rel/LINES#FE1000 -r $2/SYS/LINES#FE1000 +echo "SYS/HGRLIB"; atftp $1 --put -l rel/apple/HGRLIB#FE1000 -r $2/SYS/HGRLIB#FE1000 +echo "SYS/GRLIB"; atftp $1 --put -l rel/apple/GRLIB#FE1000 -r $2/SYS/GRLIB#FE1000 +echo "SYS/DGRLIB"; atftp $1 --put -l rel/apple/DGRLIB#FE1000 -r $2/SYS/DGRLIB#FE1000 echo "SYS/FILEIO"; atftp $1 --put -l rel/apple/FILEIO#FE1000 -r $2/SYS/FILEIO#FE1000 -echo "SYS/GRAFIX"; atftp $1 --put -l rel/apple/GRAFIX#FE1000 -r $2/SYS/GRAFIX#FE1000 echo "SYS/JOYBUZZ"; atftp $1 --put -l rel/apple/JOYBUZZ#FE1000 -r $2/SYS/JOYBUZZ#FE1000 -echo "SYS/MON"; atftp $1 --put -l rel/apple/MON#FE1000 -r $2/SYS/MON#FE1000 +echo "SYS/SNDSEQ"; atftp $1 --put -l rel/apple/SNDSEQ#FE1000 -r $2/SYS/SNDSEQ#FE1000 echo "SYS/PORTIO"; atftp $1 --put -l rel/apple/PORTIO#FE1000 -r $2/SYS/PORTIO#FE1000 -echo "SYS/SPIPORT"; atftp $1 --put -l rel/apple/SPIPORT#FE1000 -r $2/SYS/SPIPORT#FE1000 echo "SYS/UTHERNET2";atftp $1 --put -l rel/apple/UTHERNET2#FE1000 -r $2/SYS/UTHERNET2#FE1000 echo "SYS/UTHERNET"; atftp $1 --put -l rel/apple/UTHERNET#FE1000 -r $2/SYS/UTHERNET#FE1000 diff --git a/src/tftputil b/src/tftputil new file mode 100755 index 0000000..5728816 --- /dev/null +++ b/src/tftputil @@ -0,0 +1,14 @@ +#!/bin/bash + +# Core utilities +echo "SYS/ED"; atftp $1 --put -l rel/ED#FE1000 -r $2/SYS/ED#FE1000 +echo "SYS/TFTPD"; atftp $1 --put -l rel/TFTPD#FE1000 -r $2/SYS/TFTPD#FE1000 +echo "SYS/COPY"; atftp $1 --put -l rel/apple/COPY#FE1000 -r $2/SYS/COPY#FE1000 +echo "SYS/DEL"; atftp $1 --put -l rel/apple/DEL#FE1000 -r $2/SYS/DEL#FE1000 +echo "SYS/REN"; atftp $1 --put -l rel/apple/REN#FE1000 -r $2/SYS/REN#FE1000 +echo "SYS/CAT"; atftp $1 --put -l rel/apple/CAT#FE1000 -r $2/SYS/CAT#FE1000 +echo "SYS/NEWDIR"; atftp $1 --put -l rel/apple/NEWDIR#FE1000 -r $2/SYS/NEWDIR#FE1000 +echo "SYS/TYPE"; atftp $1 --put -l rel/apple/TYPE#FE1000 -r $2/SYS/TYPE#FE1000 +echo "SYS/MON"; atftp $1 --put -l rel/apple/MON#FE1000 -r $2/SYS/MON#FE1000 +echo "SYS/SOS"; atftp $1 --put -l rel/apple/SOS#FE1000 -r $2/SYS/SOS#FE1000 +echo "SYS/ZIP"; atftp $1 --put -l rel/apple/ZIP#FE1000 -r $2/SYS/ZIP#FE1000 diff --git a/src/toolsrc/codegen.c b/src/toolsrc/codegen.c index b5fcb46..f8dd98a 100755 --- a/src/toolsrc/codegen.c +++ b/src/toolsrc/codegen.c @@ -1230,6 +1230,17 @@ int crunch_seq(t_opseq **seq, int pass) freeops = 1; break; } + if (opnext->code == BINARY_CODE(SHL_TOKEN)) + { + op->code = DUP_CODE; + opnext->code = BINARY_CODE(ADD_TOKEN); + break; + } + if (opnext->code == BINARY_CODE(MUL_TOKEN) || opnext->code == BINARY_CODE(DIV_TOKEN)) + { + freeops = -2; + break; + } } switch (opnext->code) { @@ -1441,18 +1452,38 @@ int crunch_seq(t_opseq **seq, int pass) } break; case BINARY_CODE(MUL_TOKEN): - for (shiftcnt = 0; shiftcnt < 16; shiftcnt++) + if (op->val == 0) { - if (op->val == (1 << shiftcnt)) + op->code = DROP_CODE; + opnext->code = CONST_CODE; + opnext->val = 0; + } + else if (op->val == 2) + { + op->code = DUP_CODE; + opnext->code = BINARY_CODE(ADD_TOKEN); + } + else + { + // + // Constants 0, 1 and 2 handled above + // + for (shiftcnt = 2; shiftcnt < 16; shiftcnt++) { - op->val = shiftcnt; - opnext->code = BINARY_CODE(SHL_TOKEN); - break; + if (op->val == (1 << shiftcnt)) + { + op->val = shiftcnt; + opnext->code = BINARY_CODE(SHL_TOKEN); + break; + } } } break; case BINARY_CODE(DIV_TOKEN): - for (shiftcnt = 0; shiftcnt < 16; shiftcnt++) + // + // Constant 1 handled above + // + for (shiftcnt = 1; shiftcnt < 16; shiftcnt++) { if (op->val == (1 << shiftcnt)) { diff --git a/src/toolsrc/codegen.pla b/src/toolsrc/codegen.pla index 8ad0fb7..002fbe6 100644 --- a/src/toolsrc/codegen.pla +++ b/src/toolsrc/codegen.pla @@ -585,7 +585,6 @@ def init_idglobal#0 codebuff = heapalloc(codebufsz) codeptr = codebuff lastglobal = idglobal_tbl - puts("Data+Code buffer size = "); puti(codebufsz); putln end def new_idlocal(nameptr, len, type, size)#0 if idmatch(nameptr, len, @idlocal_tbl, locals); exit_err(ERR_DUP|ERR_ID); fin diff --git a/src/toolsrc/codeopt.pla b/src/toolsrc/codeopt.pla index 385cd7f..f725902 100644 --- a/src/toolsrc/codeopt.pla +++ b/src/toolsrc/codeopt.pla @@ -79,6 +79,16 @@ def crunch_seq(seq, pass) freeops = 1 break fin + if nextop->opcode == SHL_CODE + op->opcode = DUP_CODE + op->opgroup = STACK_GROUP + nextop->opcode = ADD_CODE + break + fin + if nextop->opcode == MUL_CODE or nextop->opcode == DIV_CODE + freeops = -2 + break + fin fin when nextop->opcode is NEG_CODE @@ -258,16 +268,28 @@ def crunch_seq(seq, pass) fin break is MUL_CODE - for shiftcnt = 0 to 15 - if op=>opval == 1 << shiftcnt - op=>opval = shiftcnt - nextop->opcode = SHL_CODE - break - fin - next + if op=>opval == 0 + op->opcode = DROP_CODE + op->opgroup = STACK_GROUP + nextop->opcode = CONST_CODE + nextop->opgroup = CONST_GROUP + nextop=>opval = 0 + elsif op=>opval == 2 + op->opcode = DUP_CODE + op->opgroup = STACK_GROUP + nextop->opcode = ADD_CODE + else + for shiftcnt = 2 to 15 + if op=>opval == 1 << shiftcnt + op=>opval = shiftcnt + nextop->opcode = SHL_CODE + break + fin + next + fin break is DIV_CODE - for shiftcnt = 0 to 15 + for shiftcnt = 1 to 15 if op=>opval == 1 << shiftcnt op=>opval = shiftcnt nextop->opcode = SHR_CODE diff --git a/src/toolsrc/ed.pla b/src/toolsrc/ed.pla index 22c9884..e128773 100755 --- a/src/toolsrc/ed.pla +++ b/src/toolsrc/ed.pla @@ -49,25 +49,35 @@ const keyctrlu = $95 const keyctrlv = $96 const keyctrlw = $97 const keyctrlx = $98 +const keyctrly = $99 const keyctrlz = $9A +const keytab = keyctrli +const keydetab = $9D const keydelete = $FF // // Data and text buffer constants // -const MAXLINES = 1500 +const MAXLINES = 999 const MAXLINESSIZE = MAXLINES+24 +const MAXCLIPLINES = 256 const MAXLNLEN = 79 const MAXSTRPLSIZE = $8000 //const STRPLMAPSIZE = 224 // $E0 = 28K is memory@16 bytes per bit map, 128 bytes per 8 bit map, 1K bytes per 8 byte map const pgjmp = 16 const changed = 1 const insmode = 2 -const showcurs = 4 +const gutter = 4 const uppercase = 8 +const selection = 16 +const showcurs = 32 const shiftlock = 128 // // Text screen row address array // +const scrnheight = 24 +const scrnbottom = 23 +word scrnwidth = 36 +word scrnright = 35 word txtscrn = $0400,$0480,$0500,$0580,$0600,$0680,$0700,$0780 word = $0428,$04A8,$0528,$05A8,$0628,$06A8,$0728,$07A8 word = $0450,$04D0,$0550,$05D0,$0650,$06D0,$0750,$07D0 @@ -75,17 +85,19 @@ word = $0450,$04D0,$0550,$05D0,$0650,$06D0,$0750,$07D0 // Editor variables // byte nullstr = "" +byte[80] findstr = "" byte[64] filename = "UNTITLED" byte exit = FALSE byte flags = 0 byte flash = 0 word numlines = 0 -word cutbuf = 0 +word numcliplines = 0 word arg word strplsize = MAXSTRPLSIZE -word strpool, strplmapsize, strlinbuf, strpoolmap -byte cursx, cursy, scrnleft, curscol, underchr, curschr -word keyin, cursrow, scrntop, cursptr +word strpool, strplmapsize, txtlinbuf, cliplinbuf, strpoolmap +word cursx, cursy, scrnleft, curscol +byte underchr, curschr +word keyin, cursrow, selrow, scrntop, cursptr byte a3echo = $80 byte a3noecho = $00 // @@ -117,22 +129,27 @@ STHILP LDA (SRC),Y BNE STHILP + RTS end -asm cpyln(srcstr, dststr)#0 - LDA ESTKL,X - STA DSTL - LDA ESTKH,X - STA DSTH - INX +asm lncpy(dststr, srcstr)#0 LDA ESTKL,X STA SRCL LDA ESTKH,X STA SRCH INX + LDA ESTKL,X + STA DSTL + LDA ESTKH,X + STA DSTH + INX LDY #$00 LDA (SRC),Y + CMP #80 + BCC + + LDA #79 + CLC ++ ADC #$01 ; APPEND CR TO END OF STRING + STA (DST),Y TAY - LDA #$00 - INY + LDA #$0D STA (DST),Y DEY BEQ ++ @@ -144,11 +161,43 @@ CPLNLP LDA (SRC),Y STA (DST),Y DEY BNE CPLNLP - LDA (SRC),Y -++ STA (DST),Y - RTS +++ RTS +end +asm lnupcpy(dststr, srcstr)#0 + LDA ESTKL,X + STA SRCL + LDA ESTKH,X + STA SRCH + INX + LDA ESTKL,X + STA DSTL + LDA ESTKH,X + STA DSTH + INX + LDY #$00 + LDA (SRC),Y + CMP #80 + BCC + + LDA #79 ++ STA (DST),Y + TAY + BEQ +++ +CPUPLP LDA (SRC),Y + CMP #$20 + BCS + + ADC #$60 ++ AND #$7F + CMP #$7B + BCS ++ + CMP #$61 + BCC ++ + SEC + SBC #$20 +++ STA (DST),Y + DEY + BNE CPUPLP ++++ RTS end - def bell#0 putc($07) end @@ -196,16 +245,32 @@ def strpoolalloc(size) puts("OUT OF MEMORY!") return 0 end +def striplead(strptr, chr)#0 + byte striplen -def strstripcpy(dststr, srcstr)#0 + for striplen = 1 to ^strptr + if ^(strptr + striplen) <> chr + break + fin + next + if striplen > 1 + ^strptr = ^strptr - (striplen - 1) + memcpy(strptr + 1, strptr + striplen, ^strptr) + fin +end +def striptail(strptr, chr)#0 byte strlen - strlen = ^srcstr - while ^(srcstr + strlen) == $8D or ^(srcstr + strlen) == $A0 - strlen-- - loop - ^dststr = strlen - memcpy(dststr + 1, srcstr + 1, strlen) + for strlen = ^strptr downto 1 + if ^(strptr + strlen) <> $8D and ^(strptr + strlen) <> chr + break + fin + next + ^strptr = strlen +end +def strstripcpy(dststr, srcstr)#0 + memcpy(dststr, srcstr, ^srcstr + 1) + striptail(dststr, keyspace) end def delstr(strptr)#0 byte mask, ofst @@ -223,7 +288,7 @@ def newstr(strptr) word newptr strlen = ^strptr - while ^(strptr + strlen) == $8D or ^(strptr + strlen) == $A0 + while ^(strptr + strlen) == keyenter or ^(strptr + strlen) == keyspace strlen-- loop if strlen == 0 @@ -241,7 +306,8 @@ def inittxtbuf#0 word i if not strpool - strlinbuf = heapalloc(MAXLINESSIZE*2) + txtlinbuf = heapalloc(MAXLINESSIZE*2) + cliplinbuf = heapalloc(MAXCLIPLINES*2) while isult(heapavail, strplsize) strplsize = strplsize - 4096 loop @@ -251,9 +317,17 @@ def inittxtbuf#0 strplmapsize = strplsize / 128 strpoolmap = heapalloc(strplmapsize) strpool = heapalloc(strplsize) + memset(txtlinbuf, @nullstr, MAXLINESSIZE*2) + memset(cliplinbuf, @nullstr, MAXCLIPLINES*2) + memset(strpoolmap, 0, strplmapsize) + else + for i = 0 to MAXLINESSIZE-1 + if txtlinbuf=>[i] <> @nullstr + delstr(txtlinbuf=>[i]) + txtlinbuf=>[i] = @nullstr + fin + next fin - memset(strlinbuf, @nullstr, MAXLINESSIZE*2) - memset(strpoolmap, 0, strplmapsize) numlines = 1 cursrow = 0 curscol = 0 @@ -261,7 +335,7 @@ def inittxtbuf#0 cursy = 0 scrnleft = 0 scrntop = 0 - cutbuf = 0 + flags = flags & ~selection end // // Case conversion/printing routines @@ -277,29 +351,33 @@ end def strupper(strptr)#0 byte i, chr - for i = ^strptr downto 1 - chr = (strptr).[i] - if chr & $E0 == $E0 - (strptr).[i] = chr - $E0 - fin - next + if ^strptr + for i = ^strptr downto 1 + chr = (strptr).[i] + if chr & $E0 == $E0 + (strptr).[i] = chr - $E0 + fin + next + fin end def strlower(strptr)#0 byte i, chr - for i = ^strptr downto 1 - chr = (strptr).[i] - if chr & $E0 == $00 - (strptr).[i] = chr + $E0 - fin - next + if ^strptr + for i = ^strptr downto 1 + chr = (strptr).[i] + if chr & $E0 == $00 + (strptr).[i] = chr + $E0 + fin + next + fin end def txtupper#0 word i, strptr flags = flags | uppercase for i = numlines - 1 downto 0 - strupper(strlinbuf=>[i]) + strupper(txtlinbuf=>[i]) next end def txtlower#0 @@ -307,9 +385,23 @@ def txtlower#0 flags = flags & ~uppercase for i = numlines - 1 downto 0 - strlower(strlinbuf=>[i]) + strlower(txtlinbuf=>[i]) next end +def strtonum(strptr) + word num, i + byte c + + num = 0 + for i = 1 to ^strptr + c = ^(strptr + i) & $7F + if c < '0' and c > '9' + break + fin + num = num * 10 + c - '0' + next + return num +end def nametostr(namestr, len, strptr)#0 ^strptr = len memcpy(strptr + 1, namestr, len) @@ -318,7 +410,7 @@ end // File routines // def readtxt(filename, startline)#0 - byte txtbuf[81], refnum, i, j + byte refnum, i, j, txtbuf[MAXLNLEN+2] refnum = fileio:open(filename) if refnum @@ -329,7 +421,7 @@ def readtxt(filename, startline)#0 if txtbuf sethibit(@txtbuf) if flags & uppercase; strupper(@txtbuf); fin - strlinbuf=>[numlines] = newstr(@txtbuf) + txtlinbuf=>[numlines] = newstr(@txtbuf) numlines++ fin if !(numlines & $0F); putc('.'); fin @@ -338,37 +430,47 @@ def readtxt(filename, startline)#0 // // Make sure there is a blank line at the end of the buffer // - if numlines < MAXLINES and strlinbuf=>[numlines - 1] <> @nullstr - strlinbuf=>[numlines] = @nullstr + if numlines < MAXLINES and txtlinbuf=>[numlines - 1] <> @nullstr + txtlinbuf=>[numlines] = @nullstr numlines++ fin fin + putln end def writetxt(filename)#0 - byte txtbuf[81], refnum - byte j, chr - word i, strptr + word i + byte refnum, txtbuf[MAXLNLEN+2] + // + // Remove blank lines at end of text. + // + while numlines > 1 and txtlinbuf=>[numlines - 1] == @nullstr; numlines--; loop + // + // Delete old file and re-create + // fileio:destroy(filename) fileio:create(filename, $04, $00) // full access, TXT file refnum = fileio:open(filename) if refnum == 0 + puts("\nError $"); puth(perr); puts(" opening: "); puts(filename); putln return fin // - // Remove blank lines at end of text. - // - while numlines > 1 and strlinbuf=>[numlines - 1] == @nullstr; numlines--; loop - // - // Write all the text line to the file. + // Write all the text lines to the file. // for i = 0 to numlines - 1 - cpyln(strlinbuf=>[i], @txtbuf) - txtbuf++; txtbuf[txtbuf] = $0D // Add CR to end of line - fileio:write(refnum, @txtbuf + 1, txtbuf) + lncpy(@txtbuf, txtlinbuf=>[i]) + if fileio:write(refnum, @txtbuf + 1, txtbuf) <> txtbuf + puts("\nError $"); puth(perr); puts(" writing: "); puts(filename); putln + fileio:close(refnum) + return + fin if !(i & $0F); putc('.'); fin next - fileio:close(refnum) + if fileio:close(refnum) <> FILE_ERR_OK + puts("\nError $"); puth(perr); puts(" closing: "); puts(filename) + fin + putln end // // Screen routines @@ -384,61 +486,151 @@ def drawrow(row, ofst, strptr)#0 byte numchars word scrnptr - scrnptr = txtscrn[row] + scrnptr = txtscrn[row] + (flags & gutter) if ofst >= ^strptr numchars = 0 else numchars = ^strptr - ofst fin - if numchars >= 40 - numchars = 40 + if numchars >= scrnwidth + numchars = scrnwidth else - memset(scrnptr + numchars, $A0A0, 40 - numchars) + memset(scrnptr + numchars, $A0A0, scrnwidth - numchars) fin memcpy(scrnptr, strptr + ofst + 1, numchars) end +def drawgutter(scrnrow, ofst)#0 + byte row, hilite, ofstch, huns, tens, ones + word scrnptr, scrnrow + + // + // Draw line numbers and gutter hilites + // + //ofstch = ofst ?? $80 | '<' :: keyspace + ofstch = ofst ?? '<' :: ' ' + huns, tens = divmod(scrnrow + 1, 100) + tens, ones = divmod(tens, 10) + for row = 0 to 23 + scrnptr = txtscrn[row] + if scrnrow < numlines + if flags & selection and (scrnrow >= selrow and scrnrow <= cursrow) or (scrnrow >= cursrow and scrnrow <= selrow) + hilite = $00 + elsif scrnrow == cursrow + hilite = $00 + else + hilite = $80 + fin + if huns + ^scrnptr = hilite + '0' + huns + ^(scrnptr+1) = hilite + '0' + tens + ^(scrnptr+2) = hilite + '0' + ones + ones++ + if ones > 9 + ones = 0 + tens++ + if tens > 9 + tens = 0 + huns++ + fin + fin + elsif tens + ^scrnptr = hilite + ' ' + ^(scrnptr+1) = hilite + '0' + tens + ^(scrnptr+2) = hilite + '0' + ones + ones++ + if ones > 9 + ones = 0 + tens++ + if tens > 9 + tens = 0 + huns = 1 + fin + fin + elsif ones + ^scrnptr = hilite + ' ' + ^(scrnptr+1) = hilite + ' ' + ^(scrnptr+2) = hilite + '0' + ones + ones++ + if ones > 9 + ones = 0 + tens = 1 + fin + fin + ^(scrnptr+3) = ofstch + else + *scrnptr = $A0A0 + *(scrnptr+2) = $A0A0 + fin + scrnrow++ + next +end def drawscrn(toprow, ofst)#0 - byte row, numchars + byte row, numchars, lofst word strptr, scrnptr + + lofst = flags & gutter + if lofst + drawgutter(toprow, ofst) + fin + // + // Draw text + // if ofst for row = 0 to 23 - strptr = strlinbuf=>[toprow + row] - scrnptr = txtscrn[row] + strptr = txtlinbuf=>[toprow + row] + scrnptr = txtscrn[row] + lofst if ofst >= ^strptr numchars = 0 else numchars = ^strptr - ofst fin - if numchars >= 40 - numchars = 40 + if numchars >= scrnwidth + numchars = scrnwidth else - memset(scrnptr + numchars, $A0A0, 40 - numchars) + memset(scrnptr + numchars, $A0A0, scrnwidth - numchars) fin memcpy(scrnptr, strptr + ofst + 1, numchars) next else for row = 0 to 23 - strptr = strlinbuf=>[toprow + row] - scrnptr = txtscrn[row] + strptr = txtlinbuf=>[toprow + row] + scrnptr = txtscrn[row] + lofst numchars = ^strptr - if numchars >= 40 - numchars = 40 + if numchars >= scrnwidth + numchars = scrnwidth else - memset(scrnptr + numchars, $A0A0, 40 - numchars) + memset(scrnptr + numchars, $A0A0, scrnwidth - numchars) fin memcpy(scrnptr, strptr + 1, numchars) next fin end def cursoff#0 + word scrnptr + if flags & showcurs - ^cursptr = underchr + ^cursptr = underchr + if flags & gutter + scrnptr = txtscrn[cursy] + *scrnptr = *scrnptr | $8080 + ^(scrnptr+2) = ^(scrnptr+2) | $80 + fin flags = flags & ~showcurs + fin end def curson#0 + byte lofst + word scrnptr + if !(flags & showcurs) - cursptr = txtscrn[cursy] + cursx + lofst = flags & gutter + if lofst + scrnptr = txtscrn[cursy] + *scrnptr = *scrnptr & $7F7F + ^(scrnptr+2) = ^(scrnptr+2) & $7F + fin + cursptr = txtscrn[cursy] + lofst + cursx underchr = ^cursptr ^cursptr = curschr flags = flags | showcurs @@ -459,6 +651,44 @@ def redraw#0 drawscrn(scrntop, scrnleft) curson end +def curshpos(hpos)#1 + byte needredraw + + needredraw = TRUE + if hpos < 0; hpos = 0; fin + if hpos > MAXLNLEN; hpos = MAXLNLEN; fin + curscol = hpos + cursx = curscol - scrnleft + if cursx > scrnright + cursx = scrnright + scrnleft = curscol - scrnright + elsif cursx < 0 + cursx = 0 + scrnleft = curscol + else + needredraw = FALSE + fin + return needredraw +end +def cursvpos(vpos)#1 + byte needredraw + + needredraw = TRUE + if vpos < 0; vpos = 0; fin + if vpos > numlines - 1; vpos = numlines - 1; fin + cursrow = vpos + cursy = cursrow - scrntop + if cursy > scrnbottom + cursy = scrnbottom + scrntop = cursrow - scrnbottom + elsif cursy < 0 + cursy = 0 + scrntop = cursrow + else + needredraw = FALSE + fin + return needredraw +end def curshome#0 cursoff cursrow = 0 @@ -493,6 +723,9 @@ def cursup#0 cursrow-- if cursy > 0 cursy-- + if flags & selection + drawgutter(scrntop, scrnleft) + fin else scrntop = cursrow drawscrn(scrntop, scrnleft) @@ -501,11 +734,15 @@ def cursup#0 fin end def pgup#0 - byte i - - for i = 0 to pgjmp - cursup - next + cursoff + if cursvpos(cursrow - pgjmp) + drawscrn(scrntop, scrnleft) + else + if flags & selection + drawgutter(scrntop, scrnleft) + fin + fin + curson end def cursdown#0 if cursrow < numlines - 1 @@ -513,6 +750,9 @@ def cursdown#0 cursrow++ if cursy < 23 cursy++ + if flags & selection + drawgutter(scrntop, scrnleft) + fin else scrntop = cursrow - 23 drawscrn(scrntop, scrnleft) @@ -521,11 +761,15 @@ def cursdown#0 fin end def pgdown#0 - byte i - - for i = 0 to pgjmp - cursdown - next + cursoff + if cursvpos(cursrow + pgjmp) + drawscrn(scrntop, scrnleft) + else + if flags & selection + drawgutter(scrntop, scrnleft) + fin + fin + curson end def cursleft#0 if curscol > 0 @@ -541,31 +785,123 @@ def cursleft#0 fin end def pgleft#0 - byte i + word i, strptr - for i = 0 to 7 - cursleft - next + strptr = txtlinbuf=>[cursrow] + if curscol > ^strptr + i = ^strptr + else + for i = 1 to ^strptr + if ^(strptr + i) <> keyspace + break + fin + next + i-- + if i >= curscol + i = 0 + fin + fin + cursoff + if curshpos(i) + //if curshpos(curscol - 8) + drawscrn(scrntop, scrnleft) + else + if flags & selection + drawgutter(scrntop, scrnleft) + fin + fin + curson end def cursright#0 - if curscol < 80 + if curscol < MAXLNLEN cursoff curscol++ - if cursx < 39 + if cursx < scrnright cursx++ else - scrnleft = curscol - 39 + scrnleft = curscol - scrnright drawscrn(scrntop, scrnleft) fin curson fin end def pgright#0 - byte i + word i, strptr - for i = 0 to 7 - cursright + strptr = txtlinbuf=>[cursrow] + if curscol >= ^strptr + i = curscol + 8 + else + for i = 1 to ^strptr + if ^(strptr + i) <> keyspace + break + fin + next + i-- + if curscol >= i + i = ^strptr + fin + fin + cursoff + if curshpos(i) + //if curshpos(curscol + 8) + drawscrn(scrntop, scrnleft) + else + if flags & selection + drawgutter(scrntop, scrnleft) + fin + fin + curson +end +// +// Find string in text +// +def findline(strptr, start)#1 + byte scan, i, upstr[MAXLNLEN+1] + + if ^strptr >= findstr + lnupcpy(@upstr, strptr) + for scan = start to upstr - findstr + 1 + if upstr[scan] == findstr[1] + for i = 2 to findstr + if upstr[scan + i - 1] <> findstr[i] + break + fin + next + if i > findstr + curshpos(scan - 1) + return TRUE + fin + fin + next + fin + return FALSE +end +def findtxt#0 + word f + + // + // Search from current pos to end + // + if findline(txtlinbuf=>[cursrow], curscol + 2) + return + fin + for f = cursrow + 1 to numlines - 1 + if findline(txtlinbuf=>[f], 1) + cursvpos(f) + return + fin next + // + // Search from beginning to current pos + // + for f = 0 to cursrow + if findline(txtlinbuf=>[f], 1) + cursvpos(f) + return + fin + next + bell end // // Keyboard routines @@ -621,7 +957,9 @@ def keyin3 key = keyctrlz; break is keyenter key = keyctrlf; break - is $80 | '\\' + is keytab + key = keydetab; break + is $80 | '\\' key = keydelete; break // Delete // // Map OA+keypad @@ -645,9 +983,9 @@ def keyin3 is $80 | '5' key = keyctrld; break // Del is $80 | '.' - key = keyctrlb; break // Ins + key = keyctrlc; break // Copy is $80 | '0' - key = keyctrlv; break // Copy + key = keyctrlv; break // Paste is $80 | '-' key = keyctrlx; break // Cut wend @@ -673,6 +1011,8 @@ def keyin2e key = keyctrlz; break is keyenter key = keyctrlf; break + is keytab + key = keydetab; break wend fin return key @@ -711,6 +1051,11 @@ def keyin2 key = keydelete fin break + is keyarrowright + if ^pushbttn3 < 128 + key = keytab + fin + break otherwise if key >= $C0 and flags < shiftlock if ^pushbttn3 < 128 @@ -744,29 +1089,168 @@ def setkeyin#0 keyin = @keyin2 wend end -def tabkeyin - return curscol < MAXLNLEN and curscol & $01 ?? keyspace :: 0 -end // // Printer routines // def printtxt(slot)#0 - byte txtbuf[80] + byte txtbuf[MAXLNLEN+1] word i, scrncsw scrncsw = *csw *csw = $C000 | (slot << 8) for i = 0 to numlines - 1 - cpyln(strlinbuf=>[i], @txtbuf) + lncpy(@txtbuf, txtlinbuf=>[i]) puts(@txtbuf) putln next *csw = scrncsw end +def freesel#0 + word i + + for i = 0 to numcliplines - 1 + if cliplinbuf=>[i] <> @nullstr + delstr(cliplinbuf=>[i]) + cliplinbuf=>[i] = @nullstr + fin + next + numcliplines = 0 +end +def selrange#2 + word first, last + + if flags & selection + if cursrow > selrow + first, last = selrow, cursrow + else + first, last = cursrow, selrow + fin + else + first = cursrow + last = first + fin + return first, last +end +def beginsel#0 + flags = flags ^ selection + selrow = cursrow + drawgutter(scrntop, scrnleft) +end +def copysel#0 + word firstsel, lastsel + + freesel + firstsel, lastsel = selrange + for numcliplines = 0 to lastsel - firstsel + cliplinbuf=>[numcliplines] = newstr(txtlinbuf=>[firstsel + numcliplines]) + next + flags = flags & ~selection + drawgutter(scrntop, scrnleft) +end +def cutsel#0 + word firstsel, lastsel + + freesel + firstsel, lastsel = selrange + if lastsel - firstsel < MAXCLIPLINES + for numcliplines = 0 to lastsel - firstsel + cliplinbuf=>[numcliplines] = txtlinbuf=>[firstsel + numcliplines] + next + memcpy(@txtlinbuf=>[firstsel], @txtlinbuf=>[lastsel + 1], (numlines - lastsel + 1) * 2) + numlines = numlines - numcliplines + for lastsel = numlines to numlines + numcliplines + txtlinbuf=>[lastsel] = @nullstr + next + cursrow = firstsel + if cursrow >= numlines + cursrow = numlines - 1 + fin + if cursrow < scrntop + scrntop = cursrow + fin + cursy = cursrow - scrntop + flags = flags | changed + flags = flags & ~selection + redraw + else + bell + fin +end +def pastesel#0 + word p + + if numcliplines and numcliplines + numlines < MAXLINES + memcpy(@txtlinbuf=>[cursrow + numcliplines], @txtlinbuf=>[cursrow], (numlines - cursrow) * 2) + for p = 0 to numcliplines - 1 + txtlinbuf=>[cursrow + p] = newstr(cliplinbuf=>[p]) + next + numlines = numlines + numcliplines + flags = flags | changed + redraw + else + bell + fin +end +def indentsel#0 + byte indentstr[MAXLNLEN+1], l + word firstsel, lastsel, i + + freesel + firstsel, lastsel = selrange + for i = firstsel to lastsel + l = ^(txtlinbuf=>[i]) + if l and l < MAXLNLEN - 2 + memcpy(@indentstr + 3, txtlinbuf=>[i] + 1, l) + indentstr[0] = l + 2 + indentstr[1] = keyspace + indentstr[2] = keyspace + delstr(txtlinbuf=>[i]) + txtlinbuf=>[i] = newstr(@indentstr) + flags = flags | changed + fin + next + redraw +end +def undentsel#0 + byte undentstr[MAXLNLEN+1], l + word firstsel, lastsel, i + + freesel + firstsel, lastsel = selrange + for i = firstsel to lastsel + l = ^(txtlinbuf=>[i]) + if l + memcpy(@undentstr + 1, txtlinbuf=>[i] + 1, l) + if undentstr[1] == keyspace + memcpy(@undentstr + 1, @undentstr + 2, l - 1) + l-- + if l and undentstr[1] == keyspace + memcpy(@undentstr + 1, @undentstr + 2, l - 1) + l-- + fin + undentstr[0] = l + delstr(txtlinbuf=>[i]) + txtlinbuf=>[i] = newstr(@undentstr) + flags = flags | changed + fin + fin + next + redraw +end +def autoindent(strptr)#0 + byte i + + for i = 1 to ^strptr + if ^(strptr + i) <> keyspace + break + fin + next + curshpos(i - 1) +end def openline(row) if numlines < MAXLINES - memcpy(@strlinbuf=>[row + 1], @strlinbuf=>[row], (numlines - row) * 2) - strlinbuf=>[row] = @nullstr + memcpy(@txtlinbuf=>[row + 1], @txtlinbuf=>[row], (numlines - row) * 2) + txtlinbuf=>[row] = @nullstr numlines++ flags = flags | changed return TRUE @@ -774,75 +1258,67 @@ def openline(row) bell return FALSE end -def cutline#0 - delstr(cutbuf) - cutbuf = strlinbuf=>[cursrow] - memcpy(@strlinbuf=>[cursrow], @strlinbuf=>[cursrow + 1], (numlines - cursrow) * 2) - if numlines > 1 - numlines-- - fin - flags = flags | changed - if cursrow == numlines - cursup - fin - redraw -end -def pasteline#0 - if cutbuf and numlines < MAXLINES - memcpy(@strlinbuf=>[cursrow + 1], @strlinbuf=>[cursrow], (numlines - cursrow) * 2) - strlinbuf=>[cursrow] = newstr(cutbuf) - numlines++ - flags = flags | changed - redraw - else - bell - fin -end def joinline#0 - byte joinstr[80], joinlen + byte joinstr[MAXLNLEN+1], joinlen, stripjoin[MAXLNLEN+1] if cursrow < numlines - 1 - strstripcpy(@joinstr, strlinbuf=>[cursrow]) - joinlen = joinstr + ^(strlinbuf=>[cursrow + 1]) - if joinlen < 80 - memcpy(@joinstr + joinstr + 1, strlinbuf=>[cursrow + 1] + 1, ^(strlinbuf=>[cursrow + 1])) + strstripcpy(@joinstr, txtlinbuf=>[cursrow]) + memcpy(@stripjoin, txtlinbuf=>[cursrow + 1], ^(txtlinbuf=>[cursrow + 1]) + 1) + striplead(@stripjoin, keyspace); + joinlen = joinstr + stripjoin + if joinlen <= MAXLNLEN + curshpos(joinstr) + memcpy(@joinstr + joinstr + 1, @stripjoin + 1, stripjoin) joinstr = joinlen - delstr(strlinbuf=>[cursrow]) - strlinbuf=>[cursrow] = newstr(@joinstr) - delstr(strlinbuf=>[cursrow + 1]) + delstr(txtlinbuf=>[cursrow]) + txtlinbuf=>[cursrow] = newstr(@joinstr) + delstr(txtlinbuf=>[cursrow + 1]) numlines-- - memcpy(@strlinbuf=>[cursrow + 1], @strlinbuf=>[cursrow + 2], (numlines - cursrow) * 2) + memcpy(@txtlinbuf=>[cursrow + 1], @txtlinbuf=>[cursrow + 2], (numlines - cursrow) * 2) flags = flags | changed - redraw - else - bell + return fin fin + bell end def splitline#0 - byte splitstr[80], splitlen + byte splitstr[MAXLNLEN+1], splitlen, i if openline(cursrow + 1) if curscol - splitlen = ^(strlinbuf=>[cursrow]) + splitlen = ^(txtlinbuf=>[cursrow]) if curscol < splitlen - 1 - memcpy(@splitstr + 1, strlinbuf=>[cursrow] + curscol + 1, splitlen - curscol) splitstr = splitlen - curscol - strlinbuf=>[cursrow + 1] = newstr(@splitstr) - memcpy(@splitstr + 1, strlinbuf=>[cursrow] + 1, curscol) + memcpy(@splitstr + 1, txtlinbuf=>[cursrow] + curscol + 1, splitstr) + striplead(@splitstr, keyspace) + for i = 1 to curscol + if ^(txtlinbuf=>[cursrow] + i) <> keyspace + break + fin + memcpy(@splitstr + 2, @splitstr + 1, splitstr) + splitstr[1] = keyspace + splitstr++ + next + txtlinbuf=>[cursrow + 1] = newstr(@splitstr) splitstr = curscol - delstr(strlinbuf=>[cursrow]) - strlinbuf=>[cursrow] = newstr(@splitstr) + memcpy(@splitstr + 1, txtlinbuf=>[cursrow] + 1, splitstr) + delstr(txtlinbuf=>[cursrow]) + txtlinbuf=>[cursrow] = newstr(@splitstr) + curshpos(i - 1) + else + if splitlen > 0 + for curscol = 1 to splitlen - 1 + if ^(txtlinbuf=>[cursrow] + curscol) <> keyspace + break + fin + next + curshpos(curscol - 1) + fin fin - else - strlinbuf=>[cursrow + 1] = strlinbuf=>[cursrow] - strlinbuf=>[cursrow] = @nullstr + else + txtlinbuf=>[cursrow + 1] = txtlinbuf=>[cursrow] + txtlinbuf=>[cursrow] = @nullstr fin - curscol = 0 - cursx = 0 - scrnleft = 0 - redraw - cursdown fin end def editkey(key) @@ -852,92 +1328,82 @@ def editkey(key) return FALSE end def editline(key) - byte editstr[80] word undoline + byte undopos, localchange, editstr[], editlen, editchars[MAXLNLEN+1] if (editkey(key)) - flags = flags | changed - memset(@editstr, $A0A0, 80) - strstripcpy(@editstr, strlinbuf=>[cursrow]) - undoline = strlinbuf=>[cursrow] - strlinbuf=>[cursrow] = @editstr + undopos = curscol + undoline = txtlinbuf=>[cursrow] + editlen = MAXLNLEN + memset(@editchars, $A0A0, MAXLNLEN) + memcpy(@editchars, undoline + 1, ^undoline) + txtlinbuf=>[cursrow] = @editstr + localchange = FALSE repeat - if key >= keyspace - if key == keydelete - if curscol > 0 - if curscol <= editstr - memcpy(@editstr[curscol], @editstr[curscol + 1], editstr - curscol) - editstr-- - fin - curscol-- - cursoff - if cursx > 0 - cursx-- - drawrow(cursy, scrnleft, @editstr) - else - scrnleft-- - drawscrn(scrntop, scrnleft) - fin - curson - fin - elsif curscol < MAXLNLEN - curscol++ - cursx++ - if flags & insmode - if editstr < MAXLNLEN or editstr.MAXLNLEN == $A0 - editstr++ - if curscol >= editstr - editstr = curscol - else - memcpy(@editstr[curscol + 1], @editstr[curscol], editstr - curscol) - fin - else - curscol-- - cursx-- - key = editstr[curscol] - bell - fin - else - if curscol > editstr - editstr = curscol - fin - fin - editstr[curscol] = caseconv(key) - cursoff - if cursx <= 39 - drawrow(cursy, scrnleft, @editstr) - else - scrnleft++ - cursx = 39 - drawscrn(scrntop, scrnleft) - fin - curson - else - bell - fin - elsif key == keyctrld - if curscol < editstr - strstripcpy(undoline, @editstr) - memcpy(@editstr[curscol + 1], @editstr[curscol + 2], editstr - curscol) - editstr-- + when key + is keyctrld + memcpy(@editchars[curscol], @editchars[curscol + 1], MAXLNLEN - 1 - curscol) + editchars[MAXLNLEN - 1] = keyspace cursoff drawrow(cursy, scrnleft, @editstr) curson - fin - elsif key == keyctrlr - strstripcpy(@editstr, undoline) - cursoff - drawrow(cursy, scrnleft, @editstr) - curson - fin + localchange = TRUE + break + is keyctrlr + memset(@editchars, $A0A0, MAXLNLEN) + memcpy(@editchars, undoline + 1, ^undoline) + cursoff + if curshpos(undopos) + drawscrn(scrntop, scrnleft) + else + drawrow(cursy, scrnleft, @editstr) + fin + curson + localchange = FALSE + break + is keydelete + if curscol > 0 + memcpy(@editchars[curscol - 1], @editchars[curscol], MAXLNLEN - curscol) + editchars[MAXLNLEN - 1] = keyspace + cursoff + if curshpos(curscol - 1) + drawscrn(scrntop, scrnleft) + else + drawrow(cursy, scrnleft, @editstr) + fin + curson + localchange = TRUE + fin + break + otherwise + if flags & insmode + if editchars[MAXLNLEN - 1] == keyspace + memcpy(@editchars[curscol+1], @editchars[curscol], MAXLNLEN - 1 - curscol) + else + bell + break + fin + fin + editchars[curscol] = caseconv(key) + cursoff + if curshpos(curscol + 1) + drawscrn(scrntop, scrnleft) + else + drawrow(cursy, scrnleft, @editstr) + fin + curson + localchange = TRUE + break + wend key = keyin() until not editkey(key) - if editstr - strlinbuf=>[cursrow] = newstr(@editstr) + if localchange + flags = flags | changed + delstr(undoline) + txtlinbuf=>[cursrow] = newstr(@editstr) else - strlinbuf=>[cursrow] = @nullstr + txtlinbuf=>[cursrow] = undoline fin - delstr(undoline) fin return key end @@ -967,18 +1433,34 @@ def editmode#0 curshome; break is keyctrle cursend; break + is keyctrlb + beginsel; break + is keyctrlc + copysel; break is keyctrlx - cutline; break + cutsel; break is keyctrlv - pasteline; break + pastesel; break is keyctrlf - if numlines < MAXLINES and cursrow == numlines - 1 - strlinbuf=>[numlines] = @nullstr - numlines++ + if cursrow == (numlines - 1) + if numlines < MAXLINES + numlines++ + cursdown + flags = flags | changed + drawgutter(scrntop, scrnleft) + else + bell + fin + break fin cursdown is keyctrlo openline(cursrow) + if cursrow + autoindent(txtlinbuf=>[cursrow - 1]) + else + curshpos(0) + fin redraw break is keyenter @@ -986,34 +1468,41 @@ def editmode#0 splitline else openline(cursrow + 1) - cursdown - redraw fin + autoindent(txtlinbuf=>[cursrow]) + cursvpos(cursrow + 1) + redraw break is keyctrlt - joinline; break - is keyctrli - keyin = @tabkeyin - editline(keyspace) - setkeyin - break - is keyctrlb - if flags & insmode - flags = flags & ~insmode - curschr = ' ' - else - flags = flags | insmode - curschr = '+' - fin - break - is keyctrlc - if flags & uppercase - txtlower - else - txtupper - fin + joinline redraw break + is keytab + if flags & insmode + indentsel + cursoff + if not ^(txtlinbuf=>[cursrow]) + curshpos((curscol + 2) & $FE) + else + autoindent(txtlinbuf=>[cursrow]) + fin + curson + break + fin + is keydetab + undentsel + cursoff + if not ^(txtlinbuf=>[cursrow]) + curshpos((curscol - 2) & $FFFE) + else + autoindent(txtlinbuf=>[cursrow]) + fin + curson + break + is keyctrly + flags = flags ^ insmode + curschr = flags & insmode ?? '+' :: ' ' + break is keyescape if MACHID == $F2 // Apple 3 dev_control(cmdsys.devcons, 11, @a3echo) @@ -1089,12 +1578,6 @@ def prfiles(optpath) putln return 0 end -def striplead(strptr, chr)#0 - while ^strptr and ^(strptr + 1) == chr - memcpy(strptr + 1, strptr + 2, ^strptr) - ^strptr-- - loop -end def parsecmd(strptr) byte cmd @@ -1123,19 +1606,57 @@ def chkchng end def cmdmode#0 byte slot - word cmdptr + word cmdptr, line clrscrn - puts("PLASMA Editor, Version 2.0 Dev\n") + puts("PLASMA Editor, Version 2.0 DP3\n") while not exit puts(@filename) cmdptr = gets($BA) when toupper(parsecmd(cmdptr)) - is 'A' + is 'F' // Find string + if ^cmdptr + lnupcpy(@findstr, cmdptr) + fin + findtxt + return + is 'T' // Toggle upper/lower case display + if ^cmdptr + when toupper(^(cmdptr + 1)) + is 'G' // Gutter view + flags = flags ^ gutter + if flags & gutter + scrnwidth = 36 + scrnright = 35 + else + scrnwidth = 40 + scrnright = 39 + fin + break + is 'C' // Lower case chip (Apple ][/][+ only) + if flags & uppercase + txtlower + else + txtupper + fin + break + wend + fin + return + is 'G' // Goto line # + line = strtonum(cmdptr) + if line + curshpos(0) + cursvpos(line - 1) + fin + is 'E' // Edit mode + is 0 + return + is 'A' // Append file readtxt(cmdptr, numlines) flags = flags | changed break - is 'R' + is 'R' // Read file if chkchng inittxtbuf strstripcpy(@filename, cmdptr) @@ -1143,7 +1664,7 @@ def cmdmode#0 flags = flags & ~changed fin break - is 'W' + is 'W' // Write file if ^cmdptr strstripcpy(@filename, cmdptr) fin @@ -1151,11 +1672,11 @@ def cmdmode#0 //if flags & changed; fin flags = flags & ~changed break - is 'C' + is 'C' // Catalog prfiles(cmdptr); break - is 'P' + is 'P' // Prefix fileio:setpfx(cmdptr); break - is 'H' + is 'H' // Hardcopy if ^cmdptr slot = cmdptr.1 - '0' else @@ -1163,12 +1684,13 @@ def cmdmode#0 fin printtxt(slot) break - is 'Q' + is 'Q' // Quit exit = chkchng - is 'E' - is 0 - return - is 'N' + if not exit + return + fin + break + is 'N' if chkchng inittxtbuf strstripcpy(@filename, "UNTITLED") @@ -1182,10 +1704,8 @@ def cmdmode#0 if perr puts("ERROR: $") putb(perr) - else - puts("OK") - fin putln + fin loop end // @@ -1201,9 +1721,17 @@ if ^arg strcpy(@filename, arg) puts(@filename) readtxt(@filename, 0) + arg = argNext(arg) + if ^arg + cursrow = strtonum(arg) + if cursrow + curshpos(0) + cursvpos(cursrow - 1) + fin + fin fin curschr = '+' -flags = flags | insmode +flags = flags | insmode | gutter drawscrn(scrntop, scrnleft) curson editmode diff --git a/src/toolsrc/parse.pla b/src/toolsrc/parse.pla index 5f44cf2..1e63a36 100644 --- a/src/toolsrc/parse.pla +++ b/src/toolsrc/parse.pla @@ -1211,9 +1211,8 @@ def parse_lambda return func_tag end def parse_defs - byte idlen, cfnparms, cfnvals - word type, idstr, func_tag, idptr - + byte idlen, cfnparms, cfnvals, defstr[17] + word type, idstr, func_tag, idptr, defcodeptr type = FUNC_TYPE when token is CONST_TKN @@ -1256,6 +1255,11 @@ def parse_defs func_tag = new_tag(WORD_FIXUP) new_idfunc(idstr, idlen, type, func_tag, cfnparms, infuncvals) fin + // + // Print def name + // + nametostr(idstr, idlen > 16 ?? 16 :: idlen, @defstr); puts(@defstr); putc(':') + defcodeptr = codeptr emit_tag(func_tag) new_dfd(func_tag) while parse_vars(LOCAL_TYPE); nextln; loop @@ -1276,20 +1280,26 @@ def parse_defs emit_lambdafunc(lambda_tag[cfnvals], lambda_cparms[cfnvals], lambda_seq[cfnvals]) new_dfd(lambda_tag[cfnvals]) next + puti(codeptr - defcodeptr); puts(@bytesln) + wend return token == EOL_TKN ?? TRUE :: FALSE end def parse_module#0 init_idglobal init_idlocal + puts("Data+Code buffer size = "); puti(codebufsz); putln if nextln // // Compile module // + puts("\nDATA:"); while parse_mods; nextln; loop while parse_vars(GLOBAL_TYPE); nextln; loop emit_codeseg + puti(codeptr - codebuff); puts(@bytesln) while parse_defs; nextln; loop + puts("INIT:") entrypoint = codeptr prevstmnt = 0 init_idlocal @@ -1301,6 +1311,8 @@ def parse_module#0 emit_const(0) emit_leave fin + puti(codeptr - entrypoint); puts(@bytesln) + puts("\nTotal bytes compiled: "); puti(codeptr - codebuff); putln if token <> DONE_TKN; parse_warn("Missing DONE\n"); fin //dumpsym(idglobal_tbl, globals) fin diff --git a/src/toolsrc/plasm.pla b/src/toolsrc/plasm.pla index c6ab52c..385b197 100755 --- a/src/toolsrc/plasm.pla +++ b/src/toolsrc/plasm.pla @@ -307,6 +307,7 @@ byte lambda_cnt, lambda_num byte[LAMBDANUM] lambda_cparms word[LAMBDANUM] lambda_seq, lambda_tag predef parse_constexpr#3, parse_expr(codeseq)#2, parse_lambda +byte bytesln = " bytes\n" // // Arg pointer // @@ -444,10 +445,6 @@ end // // Handy functions // -def puth(hex)#0 - putc('$') - call($F941, hex >> 8, hex, 0, 0) -end def nametostr(namestr, len, strptr)#0 ^strptr = len memcpy(strptr + 1, namestr, len) @@ -510,7 +507,7 @@ include "toolsrc/parse.pla" // // Look at command line arguments and compile module // -puts("PLASMA Compiler, Version 2.0 Dev\n") +puts("PLASMA Compiler, Version 2.0 DP3\n") arg = argNext(argFirst) if ^arg and ^(arg + 1) == '-' opt = arg + 2 @@ -583,7 +580,6 @@ if srcfile and relfile // parse_module fileio:close(srcref) - puts("\nBytes compiled: "); puti(codeptr - codebuff); putln // // Write REL file // diff --git a/src/utilsrc/apple/cat.pla b/src/utilsrc/apple/cat.pla new file mode 100644 index 0000000..e7f131e --- /dev/null +++ b/src/utilsrc/apple/cat.pla @@ -0,0 +1,184 @@ +include "inc/cmdsys.plh" +include "inc/longjmp.plh" +include "inc/args.plh" +include "inc/matchfiles.plh" +include "inc/fileio.plh" +include "inc/int32.plh" + +predef catalog(pathstr)#0 + +var arg, recurse, exit +char[64] path, wildname +res[t_fileinfo] fileinfo +res[t_fileentry] fileentry +// +// Convert byte to two hex chars +// +def putb(b)#0 + char h + + h = ((b >> 4) & $0F) + '0' + if h > '9' + h = h + 7 + fin + putc(h) + h = (b & $0F) + '0' + if h > '9' + h = h + 7 + fin + putc(h) +end +// +// Copy string with upper case conversion +// +def struprcpy(dst, src)#0 + byte i, chr + + if ^src + for i = 1 to ^src + chr = src->[i] + if chr >= 'a' and chr <= 'z' + dst->[i] = chr - 'a' + 'A' + else + dst->[i] = chr + fin + next + fin + ^dst = ^src +end +def filefrompath(filestr, pathstr)#0 + byte i + + for i = ^pathstr downto 1 + if pathstr->[i] == '/' + break + fin + next + ^filestr = ^pathstr - i + memcpy(filestr + 1, pathstr + 1 + i, ^filestr) +end +// +// Print out a directory entry +// +def printentry(entryptr)#0 + char type, pad, eofstr[12] + + puts(entryptr) + when entryptr->entry_type + is $0F // Is it a directory? + type = '/' + break + is $FF // SYSTEM file + type = '-' + break + is $FE // REL file + type = '+' + break + otherwise + type = ' ' + wend + putc(type) + for pad = ^entryptr to 14 + putc(' ') + next + putc('$'); putb(entryptr->entry_type) + puts(" $"); puth(entryptr=>entry_aux) + entryptr->entry_EOFH.1 = 0 + i32tos(entryptr+entry_EOFL, @eofstr) + for pad = eofstr to 9 + putc(' ') + next + puts(@eofstr) + putln +end +def printentries(pathstr, entries, num)#0 + byte page + + puts(pathstr); putln + puts("=NAME==========TYPE===AUX====LENGTH=\n") + page = 20 + repeat + printentry(entries) + entries = entries + t_fileentry + // + // Pause display every screenfull + // + if not page + if toupper(getc()) == 'Q' + throw(exit, TRUE) + fin + page = 22 + else + page-- + fin + num-- + until not num +end +def catalog(pathstr)#0 + char recursepath[64] + var entrylist, entryptr, entrycnt + + entrylist, entrycnt = matchList(pathstr, @wildname) + if entrylist + printentries(pathstr, entrylist, entrycnt) + if recurse + entryptr = entrylist + repeat + if entryptr->entry_type == $0F + // + // A directory, so recurse + // + strcpy(@recursepath, pathstr) + strcat(@recursepath, entryptr) + recursepath++ + recursepath[recursepath] = '/' + if toupper(getc()) == 'Q' + throw(exit, TRUE) + fin + catalog(@recursepath) + fin + entryptr = entryptr + t_fileentry + entrycnt-- + until not entrycnt + fin + heaprelease(entrylist) + fin +end +// +// Install error exit +// +exit = heapalloc(t_except) +if not except(exit) + // + // Check arguments and file types + // + arg = argNext(argFirst) + if ^arg and arg->[1] == '-' + if ^arg > 1 and toupper(arg->[2]) == 'R' + recurse = TRUE + fin + arg = argNext(arg) + fin + if ^arg + struprcpy(@path, arg) + // + // Check if cataloging a directory or volume + // + if fileio:getfileinfo(@path, @fileinfo) <> FILE_ERR_OK or (fileinfo.storage_type & $0D <> $0D) + filefrompath(@wildname, @path) + fin + path = path - wildname + fin + if not path + fileio:getpfx(@path) + fin + // + // Check if directory exists + // + if fileio:getfileinfo(@path, @fileinfo) == FILE_ERR_OK + catalog(@path) + else + puts("Unable to open: "); puts(@path); putln + fin +fin +done diff --git a/src/utilsrc/apple/copy.pla b/src/utilsrc/apple/copy.pla new file mode 100644 index 0000000..d6d9c6a --- /dev/null +++ b/src/utilsrc/apple/copy.pla @@ -0,0 +1,295 @@ +include "inc/cmdsys.plh" +include "inc/longjmp.plh" +include "inc/args.plh" +include "inc/fileio.plh" +include "inc/matchfiles.plh" + +const MAXBUFSIZE = 16384 +var arg, exit, srcfilelist, srcfileptr, srccnt +var copybuff, copyrel, copysize +byte recurse, dstlen +char[64] curpath, dstpath +char[16] srcdir +res[t_fileinfo] srcfileinfo, dstfileinfo +// +// Copy path with upper case conversion +// +def pathcpy(dst, src)#0 + byte i, chr + + if ^src + for i = 1 to ^src + chr = src->[i] + if chr >= 'a' and chr <= 'z' + dst->[i] = chr - 'a' + 'A' + else + dst->[i] = chr + fin + next + fin + ^dst = ^src +end +def abspath(abs, path)#0 + if ^path == 0 or path->[1] <> '/' + // + // Append relative path to absolute path + // + strcpy(abs, @curpath) + else + // + // Absolute path + // + ^abs = 0 + fin + strcat(abs, path) + // + // Strip trailing path seperator + // + if abs->[^abs] == '/' + ^abs-- + fin +end +def pathdiff(path1, path2)#1 + byte i, d + char[64] abs1, abs2 + + abspath(@abs1, path1) + abspath(@abs2, path2) + + if abs1 <> abs2 + return TRUE + fin + for i = 1 to abs1 + d = abs1[i] - abs2[i] + if d + return d + fin + next + return FALSE +end +def filefrompath(filestr, pathstr)#0 + byte i + + for i = ^pathstr + 1 downto 1 + if pathstr->[i] == '/' + break + fin + next + ^filestr = ^pathstr - i + memcpy(filestr + 1, pathstr + 1 + i, ^filestr) +end +// +// Check destination path +// +def chkdstpath(dstfile) + // + // Check if destination exists + // + if fileio:getfileinfo(dstfile, @dstfileinfo) == FILE_ERR_OK + // + // Check if copying into a directory + // + if dstfileinfo.storage_type & $0D == $0D + if dstfile->[^dstfile] <> '/' + // + // Add path seperator + // + ^dstfile++ + dstfile->[^dstfile] = '/' + fin + return TRUE + fin + fin + return FALSE +end +def copyfiles(srcfile, dstfile)#0 + var entrylist, entry, entrycnt, srcref, dstref, copyxfer + char[64] srcpath + char[64] srcfilepath + char[64] dstfilepath + char[16] wildname + + // + // Check if copying a directory + // + strcpy(@srcpath, srcfile) + wildname = 0 + if fileio:getfileinfo(@srcpath, @srcfileinfo) <> FILE_ERR_OK or (srcfileinfo.storage_type & $0D <> $0D) + filefrompath(@wildname, @srcpath) + srcpath = srcpath - wildname + fin + entrylist, entrycnt = matchList(@srcpath, @wildname) + if not entrylist + puts(srcfile); puts(" ???\n") + else + entry = entrylist + while entrycnt + strcpy(@srcfilepath, @srcpath) + strcat(@srcfilepath, entry) + strcpy(@dstfilepath, dstfile) + if chkdstpath(@dstfilepath) + strcat(@dstfilepath, entry) + fin + if entry->entry_type == $0F + // + // Source is a directory and not referencing the destination + // + if pathdiff(@srcfilepath, dstfile) + fileio:create(@dstfilepath, $0F, $0000) + if not chkdstpath(@dstfilepath) + puts("Unable to create directory: "); puts(@dstfilepath); putln + throw(exit, TRUE) + fin + if recurse + copyfiles(@srcfilepath, @dstfilepath) + fin + fin + else + puts(@srcfilepath) + // + // Check if destination file exists + // + if fileio:getfileinfo(@dstfilepath, @dstfileinfo) == FILE_ERR_OK + fileio:destroy(@dstfilepath) + fin + // + // Create the destination file and open for writing + // + if fileio:create(@dstfilepath, entry->entry_type, entry=>entry_aux) <> FILE_ERR_OK + puts("\nUnable to create file: "); puts(@dstfilepath); putln + throw(exit, TRUE) + fin + srcref = fileio:open(@srcfilepath) + if not srcref + puts("\nUnable to open file: "); puts(@srcfilepath); putln + throw(exit, TRUE) + fin + dstref = fileio:open(@dstfilepath) + if not dstref + puts("\nUnable to open file: "); puts(@dstfilepath); putln + throw(exit, TRUE) + fin + // + // Let the copying begin + // + repeat + copyxfer = fileio:read(srcref, copybuff, copysize) + if copyxfer + if fileio:write(dstref, copybuff, copyxfer) <> copyxfer + puts("\nError writing: "); puts(@dstfilepath); putln + throw(exit, TRUE) + fin + fin + until copyxfer == 0 + fileio:close(dstref) + fileio:close(srcref) + puts(" ==> "); puts(@dstfilepath); putln + fin + entry = entry + t_fileentry + entrycnt-- + loop + heaprelease(entrylist) + fin +end +// +// Install error exit +// +exit = heapalloc(t_except) +if not except(exit) + fileio:getpfx(@curpath) + // + // Check arguments and file types + // + arg = argNext(argFirst) + if ^arg and arg->[1] == '-' + if ^arg > 1 and toupper(arg->[2]) == 'R' + recurse = TRUE + fin + arg = argNext(arg) + fin + if ^arg + srcfilelist = heapalloc(^arg + 1) + pathcpy(srcfilelist, arg) + srccnt++ + arg = argNext(arg) + if ^arg + pathcpy(@dstpath, arg) + arg = argNext(arg) + while ^arg + // + // Add to source list + // + srcfileptr = heapalloc(dstpath + 1) + strcpy(srcfileptr, @dstpath) + srccnt++ + // + // Set new destination + // + pathcpy(@dstpath, arg) + arg = argNext(arg) + loop + if not chkdstpath(@dstpath) and (srccnt > 1 or isWildName(srcfilelist)) + puts("Destination must be a directory: "); puts(@dstpath); putln + return + fin + fileio:iobufalloc(2) // Reserve two I/O buffers + copysize = MAXBUFSIZE + while isult(heapavail, copysize + 512) + copysize = copysize / 2 + loop + copyrel = heapalloc(copysize) + if not copyrel + puts(" No available memory for copy buffer\n") + return + fin + // + // Round buffer to page boundary for faster transfers + // + copybuff = (copyrel + $FF) & $FF00 + // + // Iterate through all sources + // + srcfileptr = srcfilelist + while srccnt + dstlen = dstpath + if fileio:getfileinfo(srcfileptr, @srcfileinfo) == FILE_ERR_OK and (srcfileinfo.storage_type & $0D == $0D) + if recurse + // + // Copy directory + // + if dstpath[dstpath] <> '/' + dstpath++ + dstpath[dstpath] = '/' + fin + filefrompath(@srcdir, srcfileptr) + strcat(@dstpath, @srcdir) + if fileio:getfileinfo(@dstpath, @dstfileinfo) <> FILE_ERR_OK + fileio:create(@dstpath, $0F, $0000) + fin + if not chkdstpath(@dstpath) + puts("Destination must be a directory: "); puts(@dstpath); putln + return + fin + else + puts("Omitting directory without -r: "); puts(srcfileptr); putln + srcfileptr = srcfileptr + ^srcfileptr + 1 + srccnt-- + continue + fin + fin + // + // Copy files + // + copyfiles(srcfileptr, @dstpath) + dstpath = dstlen + srcfileptr = srcfileptr + ^srcfileptr + 1 + srccnt-- + loop + heaprelease(copyrel) + return + fin + fin + puts("Usage: +COPY + \n") +fin +fileio:close(0) +done diff --git a/src/utilsrc/apple/del.pla b/src/utilsrc/apple/del.pla new file mode 100644 index 0000000..3129ed4 --- /dev/null +++ b/src/utilsrc/apple/del.pla @@ -0,0 +1,168 @@ +include "inc/cmdsys.plh" +include "inc/longjmp.plh" +include "inc/args.plh" +include "inc/fileio.plh" +include "inc/matchfiles.plh" + +var arg, recurse, exit, filelist, fileptr, filecnt +char[64] path +res[t_fileinfo] fileinfo +// +// Copy string with upper case conversion +// +def struprcpy(dst, src)#0 + byte i, chr + + if ^src + for i = 1 to ^src + chr = src->[i] + if chr >= 'a' and chr <= 'z' + dst->[i] = chr - 'a' + 'A' + else + dst->[i] = chr + fin + next + fin + ^dst = ^src +end +def filefrompath(filestr, pathstr)#0 + byte i + + for i = ^pathstr downto 1 + if pathstr->[i] == '/' + break + fin + next + ^filestr = ^pathstr - i + memcpy(filestr + 1, pathstr + 1 + i, ^filestr) +end +// +// Check filename +// +def chkfile(file)#1 + var refnum, dirbuf, filecnt + + // + // Check if file exists + // + if fileio:getfileinfo(file, @fileinfo) == FILE_ERR_OK + // + // Check if deleting a directory + // + if fileinfo.file_type == $0F + refnum = fileio:open(file) + if refnum + // + // Check for files inside directory + // + filecnt = 0 + dirbuf = heapalloc(512) + if fileio:read(refnum, dirbuf, 512) == 512 + fileio:close(refnum) + filecnt = dirbuf=>$25 // File count in directory + fin + heaprelease(dirbuf) + if filecnt + puts("Directory not empty: "); puts(file); putln + return FALSE + fin + fin + fin + return TRUE + fin + puts("File not found: "); puts(file); putln + return FALSE +end +def delfiles(delfile)#0 + var entrylist, entry, entrycnt + char[64] delpath + char[64] delfilepath + char[16] wildname + + strcpy(@delpath, delfile) + wildname = 0 + //if fileio:getfileinfo(@delpath, @fileinfo) <> FILE_ERR_OK or fileinfo.file_type <> $0F + if delpath[delpath] <> '/' + filefrompath(@wildname, @delpath) + delpath = delpath - wildname + fin + // + // Check arguments and file types + // + entrylist, entrycnt = matchList(@delpath, @wildname) + if entrylist + entry = entrylist + while entrycnt + strcpy(@delfilepath, @delpath) + strcat(@delfilepath, entry) + // + // Check if file is a directory + // + if entry->entry_type == $0F + if recurse + strcat(@delfilepath, "/") + strcat(@delfilepath, @wildname) + delfiles(@delfilepath) + fin + strcpy(@delfilepath, @delpath) + strcat(@delfilepath, entry) + if chkfile(@delfilepath) + puts("Removing: "); puts(@delfilepath); putln + fileio:destroy(@delfilepath) + fin + else + puts("Removing: "); puts(@delfilepath); putln + fileio:destroy(@delfilepath) + fin + entry = entry + t_fileentry + entrycnt-- + loop + elsif not wildname + puts("Not found: "); puts(@delpath); puts("/"); puts(@wildname); putln + fin +end +// +// Install error exit +// +exit = heapalloc(t_except) +if not except(exit) + // + // Check arguments and file types + // + arg = argNext(argFirst) + if ^arg and arg->[1] == '-' + if ^arg > 1 and toupper(arg->[2]) == 'R' + recurse = TRUE + fin + arg = argNext(arg) + fin + if ^arg + filelist = heapmark() + while ^arg + // + // Add to file list + // + fileptr = heapalloc(^arg + 1) + struprcpy(fileptr, arg) + filecnt++ + arg = argNext(arg) + loop + fileptr = filelist + while filecnt + // + // Delete files in list + // + if recurse and fileio:getfileinfo(fileptr, @fileinfo) == FILE_ERR_OK and (fileinfo.storage_type & $0D == $0D) + strcpy(@path,fileptr) + strcat(@path, "/") + delfiles(@path) + fin + delfiles(fileptr) + fileptr = fileptr + ^fileptr + 1 + filecnt-- + loop + else + puts("Usage: +DEL +\n") + fin +fin +done diff --git a/src/libsrc/apple/jitune.pla b/src/utilsrc/apple/jitune.pla similarity index 100% rename from src/libsrc/apple/jitune.pla rename to src/utilsrc/apple/jitune.pla diff --git a/src/samplesrc/mon.pla b/src/utilsrc/apple/mon.pla similarity index 100% rename from src/samplesrc/mon.pla rename to src/utilsrc/apple/mon.pla diff --git a/src/utilsrc/apple/newdir.pla b/src/utilsrc/apple/newdir.pla new file mode 100644 index 0000000..79226b8 --- /dev/null +++ b/src/utilsrc/apple/newdir.pla @@ -0,0 +1,24 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +include "inc/fileio.plh" + +var arg +char[64] filename +res[t_fileinfo] fileinfo +// +// Check arguments and file types +// +arg = argNext(argFirst) +if ^arg + strcpy(@filename, arg) + if fileio:getfileinfo(@filename, @fileinfo) == FILE_ERR_OK + puts("File exists: "); puts(@filename); putln + else + if fileio:create(@filename, $0F, $0000) <> FILE_ERR_OK + puts("Unable to create directory: "); puts(@filename); putln + fin + fin + return +fin +puts("Usage: +NEWDIR PATH\n") +done diff --git a/src/utilsrc/apple/ren.pla b/src/utilsrc/apple/ren.pla new file mode 100644 index 0000000..f2f5f36 --- /dev/null +++ b/src/utilsrc/apple/ren.pla @@ -0,0 +1,34 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +include "inc/fileio.plh" + +var arg +char[64] oldfilename, newfilename +res[t_fileinfo] fileinfo +// +// Check arguments and file types +// +arg = argNext(argFirst) +if ^arg + strcpy(@oldfilename, arg) + if fileio:getfileinfo(@oldfilename, @fileinfo) <> FILE_ERR_OK + // + // File not found + // + puts("File not found: "); puts(@oldfilename); putln + return + fin + arg = argNext(arg) + if ^arg + strcpy(@newfilename, arg) + // + // Rename file + // + if fileio:rename(@oldfilename, @newfilename) <> FILE_ERR_OK + puts("Unable to rename: "); puts(@oldfilename); puts(" --> "); puts(@newfilename); putln + fin + return + fin +fin +puts("Usage: +REN OLDNAME NEWNAME\n") +done diff --git a/src/libsrc/apple/sos.pla b/src/utilsrc/apple/sos.pla similarity index 97% rename from src/libsrc/apple/sos.pla rename to src/utilsrc/apple/sos.pla index 69a41af..2576bf2 100644 --- a/src/libsrc/apple/sos.pla +++ b/src/utilsrc/apple/sos.pla @@ -35,10 +35,10 @@ asm sosexec(addr)#0 STA SRCL BCC + INC SRCH -+ LDA DSTL - CMP SRCL - LDA DSTH - SBC SRCH ++; LDA SRCL + CMP DSTL + LDA SRCH + SBC DSTH BCC REVCPY ; ; FORWARD COPY diff --git a/src/utilsrc/apple/type.pla b/src/utilsrc/apple/type.pla new file mode 100644 index 0000000..799f9f7 --- /dev/null +++ b/src/utilsrc/apple/type.pla @@ -0,0 +1,98 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +include "inc/fileio.plh" + +char[64] filename +res[t_fileinfo] fileinfo +var arg, type, aux +// +// Convert byte to two hex chars +// +def putb(b)#0 + char h + + h = ((b >> 4) & $0F) + '0' + if h > '9' + h = h + 7 + fin + putc(h) + h = (b & $0F) + '0' + if h > '9' + h = h + 7 + fin + putc(h) +end +def htoi(hexptr) + var val, i, n + + val = 0 + for i = 1 to ^hexptr + n = toupper(^(hexptr + i)) - '0' + if n > 9 + n = n - 7 + fin + if n > 15 or n < 0 + return val + fin + val = (val << 4) + n + next + return val +end +// +// Check arguments and file types +// +arg = argNext(argFirst) +if ^arg + strcpy(@filename, arg) + // + // Check if file exists + // + if fileio:getfileinfo(@filename, @fileinfo) == FILE_ERR_OK + // + // Check if re-typing a directory + // + if fileinfo.file_type <> $0F + // + // Check for optional overrides + // + arg = argNext(arg) + if ^arg + type = htoi(arg) + if type > 255 + puts("TYPE value out of range\n") + return + fin + // + // Can't change something into directory + // + if type <> $0F + fileinfo.file_type = type + arg = argNext(arg) + if ^arg + aux = htoi(arg) + fileinfo:aux_type = aux + fin + // + // Update file type and aux values + // + if fileio:setfileinfo(@filename, @fileinfo) == FILE_ERR_OK + if fileio:getfileinfo(@filename, @fileinfo) <> FILE_ERR_OK + puts("Unable to reload file info: "); puts(@filename) + fin + else + puts("Unable to change TYPE & AUX values: "); puts(@filename) + return + fin + fin + fin + else + puts("Unable to get file info: "); puts(@filename); putln + fin + fin + puts(@filename); putc(':') + putc('$'); putb(fileinfo.file_type); putc(' ') + putc('$'); puth(fileinfo:aux_type); putln + return +fin +puts("Usage: +TYPE FILE [HEXTYPE [HEXAUX]]\n") +done diff --git a/src/utilsrc/apple/zip.pla b/src/utilsrc/apple/zip.pla new file mode 100644 index 0000000..c8a2311 --- /dev/null +++ b/src/utilsrc/apple/zip.pla @@ -0,0 +1,51 @@ +include "inc/cmdsys.plh" +include "inc/args.plh" +// +// ZIP Chip control +// +var arg, status, slots, clock, state, cache + +byte _unlock[] +byte = $A9, $5A // LDA #$5A +byte = $8D, $5A, $C0 // STA $C05A +byte = $8D, $5A, $C0 // STA $C05A +byte = $8D, $5A, $C0 // STA $C05A +byte = $8D, $5A, $C0 // STA $C05A +byte = $60 // RTS + +def unlock#0 + (@_unlock)()#0 // Unlock regs (has to be machine code) +end +def lock#0 + ^$C05A = $A5 // Lock regs +end +arg = argNext(argFirst) +if ^arg + when toupper(arg->[1]) + is 'S' // Slow to 1 MHz + unlock + ^$C05A = $00 + lock + puts("Slow speed\n") + break + is 'F' // Enable acceleration + unlock + ^$C05B = $FF + lock + puts("Fast speed\n") + break + wend +fin +unlock +status = ^$C05B +slots = ^$C05C +clock = ^$C05D +state = ^$C05E +cache = ^$C05F +lock +puts("Status: $"); puth(status); putln +puts("Slots: $"); puth(slots); putln +puts("Clock: $"); puth(clock); putln +puts("State: $"); puth(state); putln +puts("Cache: $"); puth(cache); putln +done diff --git a/src/samplesrc/tftpd.pla b/src/utilsrc/tftpd.pla similarity index 95% rename from src/samplesrc/tftpd.pla rename to src/utilsrc/tftpd.pla index 2e8a9b4..a4a9c6d 100644 --- a/src/samplesrc/tftpd.pla +++ b/src/utilsrc/tftpd.pla @@ -260,6 +260,7 @@ def writeUDP(ipsrc, portsrc, data, len, param) end def servUDP(ipsrc, portsrc, data, len, param) byte info[24] + byte l, prefix[48] when *data is RRQ // Read request @@ -317,6 +318,17 @@ def servUDP(ipsrc, portsrc, data, len, param) // Extract filename // netscii, type, aux = mkProName(data + 2, @filename) + // + // Scan filename prefix and create + // + prefix[1] = filename[1] + for l = 2 to filename[0] + if filename[l] == '/' + prefix[0] = l-1 + fileio:create(@prefix, $0F, $0000) + fin + prefix[l] = filename[l] + next fileio:destroy(@filename) if fileio:create(@filename, type, aux) puts("Create file error: "); putb(perr); putln @@ -342,10 +354,26 @@ def servUDP(ipsrc, portsrc, data, len, param) return 0 end +def volumes#0 + word strbuf + byte i + + strbuf = heapmark() + fileio:online(0, strbuf) + for i = 0 to 15 + ^strbuf = ^strbuf & $0F + if ^strbuf + putc('/'); puts(strbuf); putln() + fin + strbuf = strbuf + 16 + next +end + +puts("TFTP Server Version 2.0 DP3\n") if !iNet:initIP() return -1 fin -puts("TFTP Server Version 2.0 Dev\n") +puts("Online volumes:\n"); volumes() portTFTP = iNet:openUDP(TFTP_PORT, @servUDP, 0) // // Alloc aligned file/io buffers @@ -358,6 +386,7 @@ buff=>datOp = $0300 // Data op repeat iNet:serviceIP() until conio:keypressed() +getc // eat keypress done Experpts from: RFC 1350, TFTP Revision 2, July 1992 diff --git a/src/vmsrc/apple/a1cmd.pla b/src/vmsrc/apple/a1cmd.pla index b93c896..5fc97b9 100755 --- a/src/vmsrc/apple/a1cmd.pla +++ b/src/vmsrc/apple/a1cmd.pla @@ -40,7 +40,7 @@ predef sext(a)#1, divmod(a,b)#2, execmod(modfile)#1 // // Exported CMDSYS table // -word version = $0110 // 01.10 +word version = $0200 // 02.00 word syspath word syscmdln word = @execmod @@ -52,7 +52,7 @@ byte perr, refauto // String pool. // byte autorun[] = "AUTORUN" -byte verstr[] = "\nPLASMA " +byte verstr[] = "\nPLASMA DP3" byte freestr[] = "MEM FREE:$" byte errorstr[] = "ERR:$" byte prompt[] = "PLASMA" diff --git a/src/vmsrc/apple/cmd.pla b/src/vmsrc/apple/cmd.pla index cd33088..13d0499 100755 --- a/src/vmsrc/apple/cmd.pla +++ b/src/vmsrc/apple/cmd.pla @@ -1192,10 +1192,8 @@ def catalog(path)#0 entry = entry + entrylen fin for i = firstblk to entriesblk - type = ^entry - if type - len = type & $0F - ^entry = len + if ^entry + ^entry = ^entry & $0F prstr(entry) type = ' ' when entry->$10 @@ -1209,7 +1207,7 @@ def catalog(path)#0 type = '+' wend cout(type) - for len = 18 - len downto 0 + for len = ^entry to 18 cout(' ') next filecnt-- @@ -1366,10 +1364,8 @@ def docmds#0 if perr prstr("ERR:$") prbyte(perr) - else - prstr("OK") + crout() fin - crout() fin prstr(pfxop(@prefix, GET_PFX)) rdstr($BA) @@ -1387,7 +1383,7 @@ heap = @lastdef // // Print PLASMA version // -prstr("PLASMA 2.0 Dev 64K\n")//; prbyte(version.1); cout('.'); prbyte(version.0); crout +prstr("PLASMA 2.0 DP3 64K\n")//; prbyte(version.1); cout('.'); prbyte(version.0); crout // // Init symbol table. // diff --git a/src/vmsrc/apple/cmdjit.pla b/src/vmsrc/apple/cmdjit.pla index c3af10c..6545556 100755 --- a/src/vmsrc/apple/cmdjit.pla +++ b/src/vmsrc/apple/cmdjit.pla @@ -39,6 +39,7 @@ end // // JIT compiler constants // +const jitcbuf = $AF00 const jitcomp = $03E2 const jitcodeptr = $03E4 const jitmod = $02F0 @@ -1256,10 +1257,8 @@ def catalog(path)#0 entry = entry + entrylen fin for i = firstblk to entriesblk - type = ^entry - if type - len = type & $0F - ^entry = len + if ^entry + ^entry = ^entry & $0F prstr(entry) type = ' ' when entry->$10 @@ -1273,7 +1272,7 @@ def catalog(path)#0 type = '+' wend cout(type) - for len = 18 - len downto 0 + for len = ^entry to 18 cout(' ') next filecnt-- @@ -1372,7 +1371,7 @@ def execsys(sysfile)#0 end def execmod(modfile)#1 byte moddci[17] - word saveheap, savexheap, savesym, saveflags, savejit + word saveheap, savexheap, savesym, saveflags perr = 1 if stodci(modfile, @moddci) @@ -1380,12 +1379,10 @@ def execmod(modfile)#1 savexheap = xheap savesym = lastsym saveflags = systemflags - savejit = *jitcodeptr if loadmod(@moddci) < modkeep lastsym = savesym xheap = savexheap heap = saveheap - *jitcodeptr = savejit fin ^lastsym = 0 systemflags = saveflags @@ -1425,6 +1422,13 @@ def docmds#0 execsys(getlnbuf) break is '+' + // + // Set JIT code pointer + // + *jitcodeptr = jitcbuf + // + // Exec module + // execmod(striptrail(getlnbuf)) // // Clean up @@ -1437,10 +1441,8 @@ def docmds#0 if perr prstr("ERR:$") prbyte(perr) - else - prstr("OK") + crout() fin - crout() fin prstr(pfxop(@prefix, GET_PFX)) rdstr($BA) @@ -1458,7 +1460,7 @@ heap = @lastdef // // Print PLASMA version // -prstr("PLASMA 2.0 Dev 128K\n")//; prbyte(version.1); cout('.'); prbyte(version.0); crout +prstr("PLASMA 2.0 DP3 128K\n")//; prbyte(version.1); cout('.'); prbyte(version.0); crout // // Init symbol table. // diff --git a/src/vmsrc/apple/plvm01.s b/src/vmsrc/apple/plvm01.s index c7e70ec..de74557 100644 --- a/src/vmsrc/apple/plvm01.s +++ b/src/vmsrc/apple/plvm01.s @@ -33,7 +33,7 @@ INTERP PLA PLA ADC #$00 STA IPH - LDY #$00 + LDY #$01 JMP FETCHOP ;* ;* ENTER INTO USER BYTECODE INTERPRETER @@ -109,7 +109,7 @@ COMP LDA #$FF ;* OPCODE TABLE ;* !ALIGN 255,0 -OPTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E +OPTBL !WORD ZERO,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 10 12 14 16 18 1A 1C 1E !WORD MINUS1,BREQ,BRNE,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E !WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E @@ -388,13 +388,17 @@ LNOT LDA ESTKL,X STA ESTKH,X JMP NEXTOP ;* -;* CONSTANT -1, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) +;* CONSTANT -1, ZERO, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) ;* MINUS1 DEX + LDA #$FF STA ESTKL,X STA ESTKH,X JMP NEXTOP +ZERO DEX + STA ESTKL,X + STA ESTKH,X + JMP NEXTOP CN DEX LSR ; A = CONST * 2 STA ESTKL,X diff --git a/src/vmsrc/apple/plvm02.s b/src/vmsrc/apple/plvm02.s index 9781c0f..3cca995 100755 --- a/src/vmsrc/apple/plvm02.s +++ b/src/vmsrc/apple/plvm02.s @@ -132,7 +132,7 @@ VMCORE = * ;* * ;**************** !ALIGN 255,0 -OPTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E +OPTBL !WORD ZERO,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 10 12 14 16 18 1A 1C 1E !WORD MINUS1,BREQ,BRNE,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E !WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E @@ -633,13 +633,17 @@ LNOT LDA ESTKL,X STA ESTKH,X JMP NEXTOP ;* -;* CONSTANT -1, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) +;* CONSTANT -1, ZERO, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) ;* MINUS1 DEX + LDA #$FF STA ESTKL,X STA ESTKH,X JMP NEXTOP +ZERO DEX + STA ESTKL,X + STA ESTKH,X + JMP NEXTOP CN DEX LSR ; A = CONST * 2 STA ESTKL,X diff --git a/src/vmsrc/apple/plvm03.s b/src/vmsrc/apple/plvm03.s index 63f782d..1c4c874 100755 --- a/src/vmsrc/apple/plvm03.s +++ b/src/vmsrc/apple/plvm03.s @@ -80,14 +80,10 @@ SEGSTART = $2000 LDA DSTH CMP #$B8 BNE - - LDA #$00 ; INIT JIT, FRAME & POOL POINTERS - STA JITCOMP - STA JITCOMP+1 - STA JITCODE + LDA #$00 ; INIT FRAME & POOL POINTERS STA PPL STA IFPL - LDA #$90 ; RESERVE 4K FOR JITCODE - STA JITCODE+1 + LDA #$A0 ; TOP OF RAM FOR FRAME POINER STA PPH STA IFPH LDX #$FF ; INIT STACK POINTER @@ -138,12 +134,11 @@ JITCOMP !WORD 0 ; $A0F2 JITCODE !WORD 0 ; $A0F4 SENTRY !WORD INTERP ; $A0F6 XENTRY !WORD XINTERP ; $A0F8 -JENTRY !WORD JITINTRP ; $A0FA ;* ;* OPCODE TABLE ;* !ALIGN 255,0 -OPTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E +OPTBL !WORD ZERO,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 10 12 14 16 18 1A 1C 1E !WORD MINUS1,BREQ,BRNE,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E !WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E @@ -161,10 +156,10 @@ OPTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 ;* INTERP PLA CLC - ADC #$01 + ADC #$01 STA IPL PLA - ADC #$00 + ADC #$00 STA IPH LDY #$00 STY IPX @@ -188,49 +183,6 @@ XINTERP PLA DEY JMP FETCHOP ;* -;* JIT PROFILING ENTRY INTO INTERPRETER -;* -JITINTRP PLA - STA TMPL - PLA - STA TMPH - LDY #$04 - LDA (TMP),Y ; DEC JIT COUNT - SEC - SBC #$01 - STA (TMP),Y - BNE - ; INTERP BYTECODE - LDA JITCOMP ; CALL JIT COMPILER - STA SRCL - LDA JITCOMP+1 - STA SRCH - INY ; LDY #$05 - LDA (SRC),Y - STA IPX - DEY - LDA (SRC),Y - STA IPH - DEY - LDA (SRC),Y - STA IPL - DEX ; ADD PARAMETER TO DEF ENTRY - LDA TMPL - SEC - SBC #$02 ; POINT TO DEF ENTRY - PHA ; AND SAVE IT FOR LATER - STA ESTKL,X - LDA TMPH - SBC #$00 - PHA - STA ESTKH,X - LDY #$00 - JSR FETCHOP ; CALL JIT COMPILER - PLA - STA TMPH - PLA - STA TMPL - JMP (TMP) ; RE-CALL ORIGINAL DEF ENTRY -;* ;* INTERNAL DIVIDE ALGORITHM ;* _NEG LDA #$00 @@ -551,13 +503,17 @@ LNOT LDA ESTKL,X STA ESTKH,X JMP NEXTOP ;* -;* CONSTANT -1, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) +;* CONSTANT -1, ZERO, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) ;* MINUS1 DEX + LDA #$FF STA ESTKL,X STA ESTKH,X JMP NEXTOP +ZERO DEX + STA ESTKL,X + STA ESTKH,X + JMP NEXTOP CN DEX LSR ; A = CONST * 2 STA ESTKL,X diff --git a/src/vmsrc/apple/plvm802.s b/src/vmsrc/apple/plvm802.s index 7c06a2a..9d11202 100644 --- a/src/vmsrc/apple/plvm802.s +++ b/src/vmsrc/apple/plvm802.s @@ -258,7 +258,7 @@ VMCORE = * ;* * ;**************** !ALIGN 255,0 -OPTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E +OPTBL !WORD ZERO,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 10 12 14 16 18 1A 1C 1E !WORD MINUS1,BREQ,BRNE,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E !WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E @@ -290,7 +290,7 @@ DINTRP PHP STX HWSP LDX #>OPTBL !IF DEBUG { - JMP SETDBG + BRA SETDBG } ELSE { STX OPPAGE LDY #$00 @@ -491,7 +491,7 @@ LCDEFCMD = *-28 ; DEFCMD IN LC MEMORY ;* * ;***************** !ALIGN 255,0 -OPXTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E +OPXTBL !WORD ZERO,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 10 12 14 16 18 1A 1C 1E !WORD MINUS1,BREQ,BRNE,LA,LLA,CB,CW,CSX ; 20 22 24 26 28 2A 2C 2E !WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E @@ -638,12 +638,12 @@ _DIV STY IPY LDY #$11 ; #BITS+1 LDX #$00 LDA NOS+2,S ; WE JSR'ED HERE SO OFFSET ACCORDINGLY - BEQ _DIVEX BPL + LDX #$81 EOR #$FFFF INC + STA TMP ; NOS,S + BEQ _DIVEX LDA TOS+2,S BPL + INX @@ -849,14 +849,14 @@ ORI INY ;+INC_IP ;* LOGICAL NOT ;* LNOT PLA - BEQ MINUS1 - PEA $0000 - JMP NEXTOP + BNE ZERO ;* -;* CONSTANT -1, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) +;* CONSTANT -1, ZERO, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) ;* MINUS1 PEA $FFFF JMP NEXTOP +ZERO PEA $0000 + JMP NEXTOP CN TXA LSR ; A = CONST * 2 PHA diff --git a/src/vmsrc/apple/plvmjit02.s b/src/vmsrc/apple/plvmjit02.s index 54c2820..a5b581a 100755 --- a/src/vmsrc/apple/plvmjit02.s +++ b/src/vmsrc/apple/plvmjit02.s @@ -206,7 +206,7 @@ VMCORE = * ;* * ;**************** !ALIGN 255,0 -OPTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E +OPTBL !WORD ZERO,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 10 12 14 16 18 1A 1C 1E !WORD MINUS1,BREQ,BRNE,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E !WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E @@ -397,7 +397,7 @@ LCDEFCMD = * ;*-28 ; DEFCMD IN LC MEMORY ;* * ;***************** !ALIGN 255,0 -OPXTBL !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E +OPXTBL !WORD ZERO,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 10 12 14 16 18 1A 1C 1E !WORD MINUS1,BREQ,BRNE,LA,LLA,CB,CW,CSX ; 20 22 24 26 28 2A 2C 2E !WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E @@ -797,13 +797,17 @@ LNOT LDA ESTKL,X STA ESTKH,X JMP NEXTOP ;* -;* CONSTANT -1, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) +;* CONSTANT -1, ZERO, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) ;* MINUS1 DEX + LDA #$FF STA ESTKL,X STA ESTKH,X JMP NEXTOP +ZERO DEX + STA ESTKL,X + STA ESTKH,X + JMP NEXTOP CN DEX LSR ; A = CONST * 2 STA ESTKL,X @@ -2170,11 +2174,11 @@ CLLBXEND JSR OPCPY CLAB INY ;+INC_IP LDA (IP),Y - STA ESTKH-2,X + STA TMPL INY ;+INC_IP LDA (IP),Y - STA ESTKH-1,X - LDA (ESTKH-2,X) + STA TMPH + LDA (TMP) DEX STA ESTKL,X STZ ESTKH,X @@ -2208,12 +2212,12 @@ CLAWEND JSR OPCPY CLABX INY ;+INC_IP LDA (IP),Y - STA ESTKH-2,X + STA TMPL INY ;+INC_IP LDA (IP),Y - STA ESTKH-1,X + STA TMPH STA ALTRDOFF - LDA (ESTKH-2,X) + LDA (TMP) DEX STA ESTKL,X STZ ESTKH,X diff --git a/src/vmsrc/apple/plvmjit03.s b/src/vmsrc/apple/plvmjit03.s new file mode 100755 index 0000000..f33a56a --- /dev/null +++ b/src/vmsrc/apple/plvmjit03.s @@ -0,0 +1,1436 @@ +;********************************************************** +;* +;* APPLE /// PLASMA INTERPETER +;* +;* SYSTEM ROUTINES AND LOCATIONS +;* +;********************************************************** +; +; HARDWARE REGISTERS +; +MEMBANK = $FFEF + !SOURCE "vmsrc/plvmzp.inc" +DVSIGN = TMP+2 +DROP = $EF +NEXTOP = $F0 +FETCHOP = NEXTOP+1 +IP = FETCHOP+1 +IPL = IP +IPH = IPL+1 +OPIDX = FETCHOP+6 +OPPAGE = OPIDX+1 +; +; XPAGE ADDRESSES +; +XPAGE = $1600 +DROPX = XPAGE+DROP +IFPX = XPAGE+IFPH +PPX = XPAGE+PPH +IPX = XPAGE+IPH +JMPTMPX = XPAGE+JMPTMP +TMPX = XPAGE+TMPH +SRCX = XPAGE+SRCH +DSTX = XPAGE+DSTH +;* +;* SOS +;* + !MACRO SOS .CMD, .LIST { + BRK + !BYTE .CMD + !WORD .LIST + } +;* +;* INTERPRETER HEADER+INITIALIZATION +;* +SEGSTART = $2000 + *= SEGSTART-$0E + !TEXT "SOS NTRP" + !WORD $0000 + !WORD SEGSTART + !WORD SEGEND-SEGSTART + + LDY #$0F ; INSTALL PAGE 0 FETCHOP ROUTINE + LDA #$00 +- LDX PAGE0,Y + STX DROP,Y + STA DROPX,Y + DEY + BPL - + LDX #$4C ; SET JMPTMP OPCODE + STX JMPTMP + STA TMPX ; CLEAR ALL EXTENDED POINTERS + STA SRCX + STA DSTX + STA PPX + STA IFPX + LDA #VMCORE + STA SRCH + LDY #$00 + STY DSTL + LDA #$A0 + STA DSTH +- LDA (SRC),Y + STA (DST),Y + INY + BNE - + INC SRCH + INC DSTH + LDA DSTH + CMP #$B8 + BNE - + LDA #$00 ; INIT JIT, FRAME & POOL POINTERS + STA JITCOMP + STA JITCOMP+1 + STA JITCODE + STA PPL + STA IFPL + LDA #$90 ; RESERVE 4K FOR JITCODE + STA JITCODE+1 + STA PPH + STA IFPH + LDX #$FF ; INIT STACK POINTER + TXS + LDX #ESTKSZ/2 ; INIT EVAL STACK INDEX + JMP SOSCMD +;PRHEX PHA +; LSR +; LSR +; LSR +; LSR +; CLC +; ADC #'0' +; CMP #':' +; BCC + +; ADC #6 +;+ STA $480 +; PLA +; AND #$0F +; ADC #'0' +; CMP #':' +; BCC + +; ADC #6 +;+ STA $481 ;$880 +;FAIL STA $0480 +; RTS +;SEGREQ !BYTE 4 +; !WORD $2000 +; !WORD $9F00 +; !BYTE $10 +; !BYTE $00 +PAGE0 = * + !PSEUDOPC DROP { +;* +;* INTERP BYTECODE INNER LOOP +;* + INX ; DROP + INY ; NEXTOP + LDA $FFFF,Y ; FETCHOP @ $F1, IP MAPS OVER $FFFF @ $F2 + STA OPIDX + JMP (OPTBL) +} +VMCORE = * + !PSEUDOPC $A000 { +TEMPBUF !FILL $F0 +CMDPARS !WORD 0 ; $A0F0 +JITCOMP !WORD 0 ; $A0F2 +JITCODE !WORD 0 ; $A0F4 +SENTRY !WORD INTERP ; $A0F6 +XENTRY !WORD XINTERP ; $A0F8 +JENTRY !WORD JITINTRP ; $A0FA +;* +;* OPCODE TABLE +;* + !ALIGN 255,0 +OPTBL !WORD ZERO,CN,CN,CN,CN,CN,CN,CN ; 00 02 04 06 08 0A 0C 0E + !WORD CN,CN,CN,CN,CN,CN,CN,CN ; 10 12 14 16 18 1A 1C 1E + !WORD MINUS1,BREQ,BRNE,LA,LLA,CB,CW,CS ; 20 22 24 26 28 2A 2C 2E + !WORD DROP,DROP2,DUP,DIVMOD,ADDI,SUBI,ANDI,ORI ; 30 32 34 36 38 3A 3C 3E + !WORD ISEQ,ISNE,ISGT,ISLT,ISGE,ISLE,BRFLS,BRTRU ; 40 42 44 46 48 4A 4C 4E + !WORD BRNCH,SEL,CALL,ICAL,ENTER,LEAVE,RET,CFFB ; 50 52 54 56 58 5A 5C 5E + !WORD LB,LW,LLB,LLW,LAB,LAW,DLB,DLW ; 60 62 64 66 68 6A 6C 6E + !WORD SB,SW,SLB,SLW,SAB,SAW,DAB,DAW ; 70 72 74 76 78 7A 7C 7E + !WORD LNOT,ADD,SUB,MUL,DIV,MOD,INCR,DECR ; 80 82 84 86 88 8A 8C 8E + !WORD NEG,COMP,BAND,IOR,XOR,SHL,SHR,IDXW ; 90 92 94 96 98 9A 9C 9E + !WORD BRGT,BRLT,INCBRLE,ADDBRLE,DECBRGE,SUBBRGE,BRAND,BROR ; A0 A2 A4 A6 A8 AA AC AE + !WORD ADDLB,ADDLW,ADDAB,ADDAW,IDXLB,IDXLW,IDXAB,IDXAW ; B0 B2 B4 B6 B8 BA BC BE + !WORD NATV ; C0 +;* +;* SYSTEM INTERPRETER ENTRYPOINT +;* +INTERP PLA + CLC + ADC #$01 + STA IPL + PLA + ADC #$00 + STA IPH + LDY #$00 + STY IPX + JMP FETCHOP +;* +;* ENTER INTO USER BYTECODE INTERPRETER +;* +XINTERP PLA + STA TMPL + PLA + STA TMPH +- LDY #$03 + LDA (TMP),Y + STA IPX + DEY + LDA (TMP),Y + STA IPH + DEY + LDA (TMP),Y + STA IPL + DEY + JMP FETCHOP +;* +;* JIT PROFILING ENTRY INTO INTERPRETER +;* +JITINTRP PLA + STA TMPL + PLA + STA TMPH + LDY #$04 + LDA (TMP),Y ; DEC JIT COUNT + SEC + SBC #$01 + STA (TMP),Y + BNE - ; INTERP BYTECODE + LDA JITCOMP ; CALL JIT COMPILER + STA SRCL + LDA JITCOMP+1 + STA SRCH + INY ; LDY #$05 + LDA (SRC),Y + STA IPX + DEY + LDA (SRC),Y + STA IPH + DEY + LDA (SRC),Y + STA IPL + DEX ; ADD PARAMETER TO DEF ENTRY + LDA TMPL + SEC + SBC #$02 ; POINT TO DEF ENTRY + PHA ; AND SAVE IT FOR LATER + STA ESTKL,X + LDA TMPH + SBC #$00 + PHA + STA ESTKH,X + LDY #$00 + JSR FETCHOP ; CALL JIT COMPILER + PLA + STA TMPH + PLA + STA TMPL + JMP (TMP) ; RE-CALL ORIGINAL DEF ENTRY +;* +;* INTERNAL DIVIDE ALGORITHM +;* +_NEG LDA #$00 + SEC + SBC ESTKL,X + STA ESTKL,X + LDA #$00 + SBC ESTKH,X + STA ESTKH,X + RTS +_DIV STY IPY + LDY #$11 ; #BITS+1 + LDA #$00 + STA TMPL ; REMNDRL + STA TMPH ; REMNDRH + STA DVSIGN + LDA ESTKH+1,X + BPL + + INX + JSR _NEG + DEX + LDA #$81 + STA DVSIGN ++ ORA ESTKL+1,X ; DVDNDL + BEQ _DIVEX + LDA ESTKH,X + BPL _DIV1 + JSR _NEG + INC DVSIGN +_DIV1 ASL ESTKL+1,X ; DVDNDL + ROL ESTKH+1,X ; DVDNDH + DEY + BCC _DIV1 +_DIVLP ROL TMPL ; REMNDRL + ROL TMPH ; REMNDRH + LDA TMPL ; REMNDRL + CMP ESTKL,X ; DVSRL + LDA TMPH ; REMNDRH + SBC ESTKH,X ; DVSRH + BCC + + STA TMPH ; REMNDRH + LDA TMPL ; REMNDRL + SBC ESTKL,X ; DVSRL + STA TMPL ; REMNDRL + SEC ++ ROL ESTKL+1,X ; DVDNDL + ROL ESTKH+1,X ; DVDNDH + DEY + BNE _DIVLP +_DIVEX INX + LDY IPY + RTS +;* +;* MUL TOS-1 BY TOS +;* +MUL STY IPY + LDY #$10 + LDA ESTKL+1,X + EOR #$FF + STA TMPL + LDA ESTKH+1,X + EOR #$FF + STA TMPH + LDA #$00 + STA ESTKL+1,X ; PRODL +; STA ESTKH+1,X ; PRODH +_MULLP LSR TMPH ; MULTPLRH + ROR TMPL ; MULTPLRL + BCS + + STA ESTKH+1,X ; PRODH + LDA ESTKL,X ; MULTPLNDL + ADC ESTKL+1,X ; PRODL + STA ESTKL+1,X + LDA ESTKH,X ; MULTPLNDH + ADC ESTKH+1,X ; PRODH ++ ASL ESTKL,X ; MULTPLNDL + ROL ESTKH,X ; MULTPLNDH + DEY + BNE _MULLP + STA ESTKH+1,X ; PRODH + LDY IPY + JMP DROP +;* +;* NEGATE TOS +;* +NEG JSR _NEG + JMP NEXTOP +;* +;* DIV TOS-1 BY TOS +;* +DIV JSR _DIV + LSR DVSIGN ; SIGN(RESULT) = (SIGN(DIVIDEND) + SIGN(DIVISOR)) & 1 + BCS NEG + JMP NEXTOP +;* +;* MOD TOS-1 BY TOS +;* +MOD JSR _DIV + LDA TMPL ; REMNDRL + STA ESTKL,X + LDA TMPH ; REMNDRH + STA ESTKH,X + LDA DVSIGN ; REMAINDER IS SIGN OF DIVIDEND + BMI NEG + JMP NEXTOP +;* +;* DIVMOD TOS-1 BY TOS +;* +DIVMOD JSR _DIV + LSR DVSIGN ; SIGN(RESULT) = (SIGN(DIVIDEND) + SIGN(DIVISOR)) & 1 + BCC + + JSR _NEG ++ DEX + LDA TMPL ; REMNDRL + STA ESTKL,X + LDA TMPH ; REMNDRH + STA ESTKH,X + ASL DVSIGN ; REMAINDER IS SIGN OF DIVIDEND + BMI NEG + JMP NEXTOP +;* +;* INCREMENT TOS +;* +INCR INC ESTKL,X + BNE + + INC ESTKH,X ++ JMP NEXTOP +;* +;* DECREMENT TOS +;* +DECR LDA ESTKL,X + BNE + + DEC ESTKH,X ++ DEC ESTKL,X + JMP NEXTOP +;* +;* ADD TOS TO TOS-1 +;* +ADD LDA ESTKL,X + CLC + ADC ESTKL+1,X + STA ESTKL+1,X + LDA ESTKH,X + ADC ESTKH+1,X + STA ESTKH+1,X + JMP DROP +;* +;* SUB TOS FROM TOS-1 +;* +SUB LDA ESTKL+1,X + SEC + SBC ESTKL,X + STA ESTKL+1,X + LDA ESTKH+1,X + SBC ESTKH,X + STA ESTKH+1,X + JMP DROP +; +;* +;* SHIFT TOS LEFT BY 1, ADD TO TOS-1 +;* +IDXW LDA ESTKL,X + ASL + ROL ESTKH,X + CLC + ADC ESTKL+1,X + STA ESTKL+1,X + LDA ESTKH,X + ADC ESTKH+1,X + STA ESTKH+1,X + JMP DROP +;* +;* BITWISE COMPLIMENT TOS +;* +COMP LDA #$FF + EOR ESTKL,X + STA ESTKL,X + LDA #$FF + EOR ESTKH,X + STA ESTKH,X + JMP NEXTOP +;* +;* BITWISE AND TOS TO TOS-1 +;* +BAND LDA ESTKL+1,X + AND ESTKL,X + STA ESTKL+1,X + LDA ESTKH+1,X + AND ESTKH,X + STA ESTKH+1,X + JMP DROP +;* +;* INCLUSIVE OR TOS TO TOS-1 +;* +IOR LDA ESTKL+1,X + ORA ESTKL,X + STA ESTKL+1,X + LDA ESTKH+1,X + ORA ESTKH,X + STA ESTKH+1,X + JMP DROP +;* +;* EXLUSIVE OR TOS TO TOS-1 +;* +XOR LDA ESTKL+1,X + EOR ESTKL,X + STA ESTKL+1,X + LDA ESTKH+1,X + EOR ESTKH,X + STA ESTKH+1,X + JMP DROP +;* +;* SHIFT TOS-1 LEFT BY TOS +;* +SHL STY IPY + LDA ESTKL,X + CMP #$08 + BCC + + LDY ESTKL+1,X + STY ESTKH+1,X + LDY #$00 + STY ESTKL+1,X + SBC #$08 ++ TAY + BEQ + + LDA ESTKL+1,X +- ASL + ROL ESTKH+1,X + DEY + BNE - + STA ESTKL+1,X ++ LDY IPY + JMP DROP +;* +;* SHIFT TOS-1 RIGHT BY TOS +;* +SHR STY IPY + LDA ESTKL,X + CMP #$08 + BCC ++ + LDY ESTKH+1,X + STY ESTKL+1,X + CPY #$80 + LDY #$00 + BCC + + DEY ++ STY ESTKH+1,X + SEC + SBC #$08 +++ TAY + BEQ + + LDA ESTKH+1,X +- CMP #$80 + ROR + ROR ESTKL+1,X + DEY + BNE - + STA ESTKH+1,X ++ LDY IPY + JMP DROP +;* +;* DUPLICATE TOS +;* +DUP DEX + LDA ESTKL+1,X + STA ESTKL,X + LDA ESTKH+1,X + STA ESTKH,X + JMP NEXTOP +;* +;* ADD IMMEDIATE TO TOS +;* +ADDI INY ;+INC_IP + LDA (IP),Y + CLC + ADC ESTKL,X + STA ESTKL,X + BCC + + INC ESTKH,X ++ JMP NEXTOP +;* +;* SUB IMMEDIATE FROM TOS +;* +SUBI INY ;+INC_IP + LDA ESTKL,X + SEC + SBC (IP),Y + STA ESTKL,X + BCS + + DEC ESTKH,X ++ JMP NEXTOP +;* +;* AND IMMEDIATE TO TOS +;* +ANDI INY ;+INC_IP + LDA (IP),Y + AND ESTKL,X + STA ESTKL,X + LDA #$00 + STA ESTKH,X + JMP NEXTOP +;* +;* IOR IMMEDIATE TO TOS +;* +ORI INY ;+INC_IP + LDA (IP),Y + ORA ESTKL,X + STA ESTKL,X + JMP NEXTOP +;* +;* LOGICAL NOT +;* +LNOT LDA ESTKL,X + ORA ESTKH,X + BEQ + + LDA #$00 + STA ESTKL,X + STA ESTKH,X + JMP NEXTOP +;* +;* CONSTANT -1, ZERO, NYBBLE, BYTE, $FF BYTE, WORD (BELOW) +;* +MINUS1 DEX ++ LDA #$FF + STA ESTKL,X + STA ESTKH,X + JMP NEXTOP +ZERO DEX + STA ESTKL,X + STA ESTKH,X + JMP NEXTOP +CN DEX + LSR ; A = CONST * 2 + STA ESTKL,X + LDA #$00 + STA ESTKH,X + JMP NEXTOP +CFFB LDA #$FF + DEX + STA ESTKH,X + INY ;+INC_IP + LDA (IP),Y + STA ESTKL,X + JMP NEXTOP +CB LDA #$00 + DEX + STA ESTKH,X + INY ;+INC_IP + LDA (IP),Y + STA ESTKL,X + JMP NEXTOP +;* +;* LOAD ADDRESS & LOAD CONSTANT WORD (SAME THING, WITH OR WITHOUT FIXUP) +;* +- TYA ; RENORMALIZE IP + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ LDY #$FF +LA INY ;+INC_IP + BMI - + DEX + LDA (IP),Y + STA ESTKL,X + INY + LDA (IP),Y + STA ESTKH,X + JMP NEXTOP +CW DEX + INY ;+INC_IP + LDA (IP),Y + STA ESTKL,X + INY + LDA (IP),Y + STA ESTKH,X + JMP NEXTOP +;* +;* CONSTANT STRING +;* +CS DEX + ;INY ;+INC_IP + TYA ; NORMALIZE IP + SEC + ADC IPL + STA IPL + LDA #$00 + TAY + ADC IPH + STA IPH + LDA PPL ; SCAN POOL FOR STRING ALREADY THERE + STA TMPL + LDA PPH + STA TMPH +_CMPPS ;LDA TMPH ; CHECK FOR END OF POOL + CMP IFPH + BCC _CMPS ; CHECK FOR MATCHING STRING + BNE _CPYS ; BEYOND END OF POOL, COPY STRING OVER + LDA TMPL + CMP IFPL + BCS _CPYS ; AT OR BEYOND END OF POOL, COPY STRING OVER +_CMPS LDA (TMP),Y ; COMPARE STRINGS FROM AUX MEM TO STRINGS IN MAIN MEM + CMP (IP),Y ; COMPARE STRING LENGTHS + BNE _CNXTS1 + TAY +_CMPCS LDA (TMP),Y ; COMPARE STRING CHARS FROM END + CMP (IP),Y + BNE _CNXTS + DEY + BNE _CMPCS + LDA TMPL ; MATCH - SAVE EXISTING ADDR ON ESTK AND MOVE ON + STA ESTKL,X + LDA TMPH + STA ESTKH,X + BNE _CEXS +_CNXTS LDY #$00 + LDA (TMP),Y +_CNXTS1 SEC + ADC TMPL + STA TMPL + LDA #$00 + ADC TMPH + STA TMPH + BNE _CMPPS +_CPYS LDA (IP),Y ; COPY STRING FROM AUX TO MAIN MEM POOL + TAY ; MAKE ROOM IN POOL AND SAVE ADDR ON ESTK + EOR #$FF + CLC + ADC PPL + STA PPL + STA ESTKL,X + LDA #$FF + ADC PPH + STA PPH + STA ESTKH,X ; COPY STRING FROM AUX MEM BYTECODE TO MAIN MEM POOL +_CPYS1 LDA (IP),Y ; ALTRD IS ON, NO NEED TO CHANGE IT HERE + STA (PP),Y ; ALTWR IS OFF, NO NEED TO CHANGE IT HERE + DEY + CPY #$FF + BNE _CPYS1 + INY +_CEXS LDA (IP),Y ; SKIP TO NEXT OP ADDR AFTER STRING + TAY + JMP NEXTOP +;* +;* LOAD VALUE FROM ADDRESS TAG +;* +LB LDA ESTKL,X + STA ESTKH-1,X + LDA (ESTKH-1,X) + STA ESTKL,X + LDA #$00 + STA ESTKH,X + JMP NEXTOP +LW LDA ESTKL,X + STA ESTKH-1,X + LDA (ESTKH-1,X) + STA ESTKL,X + INC ESTKH-1,X + BNE + + INC ESTKH,X ++ LDA (ESTKH-1,X) + STA ESTKH,X + JMP NEXTOP +;* +;* LOAD ADDRESS OF LOCAL FRAME OFFSET +;* +- TYA ; RENORMALIZE IP + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ LDY #$FF +LLA INY ;+INC_IP + BMI - + LDA (IP),Y + DEX + CLC + ADC IFPL + STA ESTKL,X + LDA #$00 + ADC IFPH + STA ESTKH,X + JMP NEXTOP +;* +;* LOAD VALUE FROM LOCAL FRAME OFFSET +;* +LLB INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + DEX + LDA (IFP),Y + STA ESTKL,X + LDA #$00 + STA ESTKH,X + LDY IPY + JMP NEXTOP +LLW INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + DEX + LDA (IFP),Y + STA ESTKL,X + INY + LDA (IFP),Y + STA ESTKH,X + LDY IPY + JMP NEXTOP +;* +;* ADD VALUE FROM LOCAL FRAME OFFSET +;* +ADDLB INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + LDA (IFP),Y + CLC + ADC ESTKL,X + STA ESTKL,X + BCC + + INC ESTKH,X ++ LDY IPY + JMP NEXTOP +ADDLW INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + LDA (IFP),Y + CLC + ADC ESTKL,X + STA ESTKL,X + INY + LDA (IFP),Y + ADC ESTKH,X + STA ESTKH,X + LDY IPY + JMP NEXTOP +;* +;* INDEX VALUE FROM LOCAL FRAME OFFSET +;* +IDXLB INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + LDA (IFP),Y + LDY #$00 + ASL + BCC + + INY + CLC ++ ADC ESTKL,X + STA ESTKL,X + TYA + ADC ESTKH,X + STA ESTKH,X + LDY IPY + JMP NEXTOP +IDXLW INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + LDA (IFP),Y + ASL + STA TMPL + INY + LDA (IFP),Y + ROL + STA TMPH + LDA TMPL + CLC + ADC ESTKL,X + STA ESTKL,X + LDA TMPH + ADC ESTKH,X + STA ESTKH,X + LDY IPY + JMP NEXTOP +;* +;* LOAD VALUE FROM ABSOLUTE ADDRESS +;* +LAB INY ;+INC_IP + LDA (IP),Y + STA ESTKH-2,X + INY ;+INC_IP + LDA (IP),Y + STA ESTKH-1,X + LDA (ESTKH-2,X) + DEX + STA ESTKL,X + LDA #$00 + STA ESTKH,X + JMP NEXTOP +LAW INY ;+INC_IP + LDA (IP),Y + STA TMPL + INY ;+INC_IP + LDA (IP),Y + STA TMPH + STY IPY + LDY #$00 + LDA (TMP),Y + DEX + STA ESTKL,X + INY + LDA (TMP),Y + STA ESTKH,X + LDY IPY + JMP NEXTOP +;* +;* ADD VALUE FROM ABSOLUTE ADDRESS +;* +ADDAB INY ;+INC_IP + LDA (IP),Y + STA ESTKH-2,X + INY ;+INC_IP + LDA (IP),Y + STA ESTKH-1,X + LDA (ESTKH-2,X) + CLC + ADC ESTKL,X + STA ESTKL,X + BCC + + INC ESTKH,X ++ JMP NEXTOP +ADDAW INY ;+INC_IP + LDA (IP),Y + STA SRCL + INY ;+INC_IP + LDA (IP),Y + STA SRCH + STY IPY + LDY #$00 + LDA (SRC),Y + CLC + ADC ESTKL,X + STA ESTKL,X + INY + LDA (SRC),Y + ADC ESTKH,X + STA ESTKH,X + LDY IPY + JMP NEXTOP +;* +;* INDEX VALUE FROM ABSOLUTE ADDRESS +;* +IDXAB INY ;+INC_IP + LDA (IP),Y + STA ESTKH-2,X + INY ;+INC_IP + LDA (IP),Y + STA ESTKH-1,X + LDA (ESTKH-2,X) + STY IPY + LDY #$00 + ASL + BCC + + INY + CLC ++ ADC ESTKL,X + STA ESTKL,X + TYA + ADC ESTKH,X + STA ESTKH,X + LDY IPY + JMP NEXTOP +IDXAW INY ;+INC_IP + LDA (IP),Y + STA SRCL + INY ;+INC_IP + LDA (IP),Y + STA SRCH + STY IPY + LDY #$00 + LDA (SRC),Y + ASL + STA TMPL + INY + LDA (SRC),Y + ROL + STA TMPH + LDA TMPL + CLC + ADC ESTKL,X + STA ESTKL,X + LDA TMPH + ADC ESTKH,X + STA ESTKH,X + LDY IPY + JMP NEXTOP +;* +;* STORE VALUE TO ADDRESS +;* +SB LDA ESTKL,X + STA ESTKH-1,X + LDA ESTKL+1,X + STA (ESTKH-1,X) + INX + JMP DROP +SW LDA ESTKL,X + STA ESTKH-1,X + LDA ESTKL+1,X + STA (ESTKH-1,X) + LDA ESTKH+1,X + INC ESTKH-1,X + BNE + + INC ESTKH,X ++ STA (ESTKH-1,X) +;* +;* DROP TOS, TOS-1 +;* +DROP2 INX + JMP DROP +;* +;* STORE VALUE TO LOCAL FRAME OFFSET +;* +SLB INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + LDA ESTKL,X + STA (IFP),Y + LDY IPY + BMI FIXDROP + JMP DROP +SLW INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + LDA ESTKL,X + STA (IFP),Y + INY + LDA ESTKH,X + STA (IFP),Y + LDY IPY + BMI FIXDROP + JMP DROP +FIXDROP TYA + LDY #$00 + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ JMP DROP +;* +;* STORE VALUE TO LOCAL FRAME OFFSET WITHOUT POPPING STACK +;* +DLB INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + LDA ESTKL,X + STA (IFP),Y + LDA #$00 + STA ESTKH,X + LDY IPY + JMP NEXTOP +DLW INY ;+INC_IP + LDA (IP),Y + STY IPY + TAY + LDA ESTKL,X + STA (IFP),Y + INY + LDA ESTKH,X + STA (IFP),Y + LDY IPY + JMP NEXTOP +;* +;* STORE VALUE TO ABSOLUTE ADDRESS +;* +- TYA ; RENORMALIZE IP + CLC + ADC IPL + STA IPL + BCC + + INC IPH ++ LDY #$FF +SAB INY ;+INC_IP + BMI - + LDA (IP),Y + STA ESTKH-2,X + INY ;+INC_IP + LDA (IP),Y + STA ESTKH-1,X + LDA ESTKL,X + STA (ESTKH-2,X) + JMP DROP +SAW INY ;+INC_IP + LDA (IP),Y + STA TMPL + INY ;+INC_IP + LDA (IP),Y + STA TMPH + STY IPY + LDY #$00 + LDA ESTKL,X + STA (TMP),Y + INY + LDA ESTKH,X + STA (TMP),Y + LDY IPY + BMI FIXDROP + JMP DROP +;* +;* STORE VALUE TO ABSOLUTE ADDRESS WITHOUT POPPING STACK +;* +DAB INY ;+INC_IP + LDA (IP),Y + STA ESTKH-2,X + INY ;+INC_IP + LDA (IP),Y + STA ESTKH-1,X + LDA ESTKL,X + STA (ESTKH-2,X) + LDA #$00 + STA ESTKH,X + JMP NEXTOP +DAW INY ;+INC_IP + LDA (IP),Y + STA TMPL + INY ;+INC_IP + LDA (IP),Y + STA TMPH + STY IPY + LDY #$00 + LDA ESTKL,X + STA (TMP),Y + INY + LDA ESTKH,X + STA (TMP),Y + LDY IPY + JMP NEXTOP +;* +;* COMPARES +;* +ISEQ LDA ESTKL,X + CMP ESTKL+1,X + BNE ISFLS + LDA ESTKH,X + CMP ESTKH+1,X + BNE ISFLS +ISTRU LDA #$FF + STA ESTKL+1,X + STA ESTKH+1,X + JMP DROP +ISNE LDA ESTKL,X + CMP ESTKL+1,X + BNE ISTRU + LDA ESTKH,X + CMP ESTKH+1,X + BNE ISTRU +ISFLS LDA #$00 + STA ESTKL+1,X + STA ESTKH+1,X + JMP DROP +ISGE LDA ESTKL+1,X + CMP ESTKL,X + LDA ESTKH+1,X + SBC ESTKH,X + BVS + + BPL ISTRU + BMI ISFLS ++ +- BPL ISFLS + BMI ISTRU +ISLE LDA ESTKL,X + CMP ESTKL+1,X + LDA ESTKH,X + SBC ESTKH+1,X + BVS - + BPL ISTRU + BMI ISFLS +ISGT LDA ESTKL,X + CMP ESTKL+1,X + LDA ESTKH,X + SBC ESTKH+1,X + BVS + + BMI ISTRU + BPL ISFLS ++ +- BMI ISFLS + BPL ISTRU +ISLT LDA ESTKL+1,X + CMP ESTKL,X + LDA ESTKH+1,X + SBC ESTKH,X + BVS - + BMI ISTRU + BPL ISFLS +;* +;* BRANCHES +;* +SEL INX + TYA ; FLATTEN IP + SEC + ADC IPL + STA TMPL + LDA #$00 + TAY + ADC IPH + STA TMPH ; ADD CASEBLOCK OFFSET + LDA IPX ; COPY XBYTE FROM IP + STA TMPX + LDA (TMP),Y + ;CLC ; BETTER NOT CARRY OUT OF IP+Y + ADC TMPL + STA IPL + INY + LDA (TMP),Y + ADC TMPH + STA IPH + DEY + STY TMPX ; CLEAR TMPX + LDA (IP),Y + STA TMPL ; CASE COUNT + INC IPL + BNE CASELP + INC IPH +CASELP LDA ESTKL-1,X + CMP (IP),Y + BEQ + + LDA ESTKH-1,X + INY + SBC (IP),Y + BMI CASEEND +- INY + INY + DEC TMPL + BEQ FIXNEXT + INY + BNE CASELP + INC IPH + BNE CASELP ++ LDA ESTKH-1,X + INY + SBC (IP),Y + BEQ BRNCH + BPL - +CASEEND LDA #$00 + STA TMPH + DEC TMPL + LDA TMPL + ASL ; SKIP REMAINING CASES + ROL TMPH + ASL + ROL TMPH +; CLC + ADC IPL + STA IPL + LDA TMPH + ADC IPH + STA IPH + INY + INY +FIXNEXT TYA + LDY #$00 + SEC + ADC IPL + STA IPL + BCC + + INC IPH ++ JMP FETCHOP +BRAND LDA ESTKL,X + ORA ESTKH,X + BEQ BRNCH + INX ; DROP LEFT HALF OF AND + BNE NOBRNCH +BROR LDA ESTKL,X + ORA ESTKH,X + BNE BRNCH + INX ; DROP LEFT HALF OF OR + BNE NOBRNCH +BREQ INX + INX + LDA ESTKL-2,X + CMP ESTKL-1,X + BNE NOBRNCH + LDA ESTKH-2,X + CMP ESTKH-1,X + BEQ BRNCH + BNE NOBRNCH +BRNE INX + INX + LDA ESTKL-2,X + CMP ESTKL-1,X + BNE BRNCH + LDA ESTKH-2,X + CMP ESTKH-1,X + BNE BRNCH + BEQ NOBRNCH +BRTRU INX + LDA ESTKH-1,X + ORA ESTKL-1,X + BNE BRNCH +NOBRNCH INY ;+INC_IP + INY ;+INC_IP + BMI FIXNEXT + JMP NEXTOP +BRFLS INX + LDA ESTKH-1,X + ORA ESTKL-1,X + BNE NOBRNCH +BRNCH TYA ; FLATTEN IP + SEC + ADC IPL + STA TMPL + LDA #$00 + TAY + ADC IPH + STA TMPH ; ADD BRANCH OFFSET + LDA IPX ; COPY XBYTE FROM IP + STA TMPX + LDA (TMP),Y + ;CLC ; BETTER NOT CARRY OUT OF IP+Y + ADC TMPL + STA IPL + INY + LDA (TMP),Y + ADC TMPH + STA IPH + DEY + STY TMPX ; CLEAR TMPX + JMP FETCHOP +;* +;* FOR LOOPS PUT TERMINAL VALUE AT ESTK+1 AND CURRENT COUNT ON ESTK +;* +BRGT LDA ESTKL+1,X + CMP ESTKL,X + LDA ESTKH+1,X + SBC ESTKH,X + BVS ++ +- BPL NOBRNCH + BMI BRNCH +BRLT LDA ESTKL,X + CMP ESTKL+1,X + LDA ESTKH,X + SBC ESTKH+1,X + BVS ++ + BPL NOBRNCH + BMI BRNCH +DECBRGE DEC ESTKL,X + LDA ESTKL,X + CMP #$FF + BNE + + DEC ESTKH,X +_BRGE LDA ESTKL,X ++ CMP ESTKL+1,X + LDA ESTKH,X + SBC ESTKH+1,X + BVS - + BPL BRNCH + BMI NOBRNCH +INCBRLE INC ESTKL,X + BNE _BRLE + INC ESTKH,X +_BRLE LDA ESTKL+1,X + CMP ESTKL,X + LDA ESTKH+1,X + SBC ESTKH,X + BVS - +++ BPL BRNCH + BMI NOBRNCH +SUBBRGE LDA ESTKL+1,X + SEC + SBC ESTKL,X + STA ESTKL+1,X + LDA ESTKH+1,X + SBC ESTKH,X + STA ESTKH+1,X + INX + BNE _BRGE +ADDBRLE LDA ESTKL,X + CLC + ADC ESTKL+1,X + STA ESTKL+1,X + LDA ESTKH,X + ADC ESTKH+1,X + STA ESTKH+1,X + INX + BNE _BRLE +;* +;* INDIRECT CALL TO ADDRESS (NATIVE CODE) +;* +ICAL LDA ESTKL,X + STA ICALADR+1 + LDA ESTKH,X + STA ICALADR+2 + INX + TYA + SEC + ADC IPL + PHA + LDA IPH + ADC #$00 + PHA + LDA IPX + PHA +ICALADR JSR $FFFF + PLA + STA IPX + PLA + STA IPH + PLA + STA IPL + LDY #$00 + JMP FETCHOP +;* +;* CALL INTO ABSOLUTE ADDRESS (NATIVE CODE) +;* +CALL INY ;+INC_IP + LDA (IP),Y + STA CALLADR+1 + INY ;+INC_IP + LDA (IP),Y + STA CALLADR+2 +_CALL TYA + SEC + ADC IPL + PHA + LDA IPH + ADC #$00 + PHA + LDA IPX + PHA +CALLADR JSR $FFFF + PLA + STA IPX + PLA + STA IPH + PLA + STA IPL + LDY #$00 + JMP FETCHOP +;* +;* ENTER FUNCTION WITH FRAME SIZE AND PARAM COUNT +;* +ENTER LDA IFPH + PHA ; SAVE ON STACK FOR LEAVE + LDA IFPL + PHA + INY + LDA (IP),Y + EOR #$FF + SEC + ADC PPL + STA PPL + STA IFPL + LDA #$FF + ADC PPH + STA PPH + STA IFPH + INY + LDA (IP),Y + BEQ + + ASL + TAY +- LDA ESTKH,X + DEY + STA (IFP),Y + LDA ESTKL,X + INX + DEY + STA (IFP),Y + BNE - ++ LDY #$03 + JMP FETCHOP +;* +;* LEAVE FUNCTION +;* +LEAVE INY ;+INC_IP + LDA (IP),Y + CLC + ADC IFPL + STA PPL + LDA #$00 + ADC IFPH + STA PPH + PLA ; RESTORE PREVIOUS FRAME + STA IFPL + PLA + STA IFPH +RET RTS +;* +;* RETURN TO NATIVE CODE +;* +NATV TYA ; FLATTEN IP + SEC + ADC IPL + STA IPL + BCS + + JMP (IP) ++ INC IPH + JMP (IP) +SOSCMD = * + !SOURCE "vmsrc/apple/sossysjit.a" + +} +SEGEND = * diff --git a/src/vmsrc/apple/soscmd.pla b/src/vmsrc/apple/soscmd.pla index 6150543..f433a5d 100755 --- a/src/vmsrc/apple/soscmd.pla +++ b/src/vmsrc/apple/soscmd.pla @@ -1,81 +1,8 @@ include "inc/cmdsys.plh" // -// JIT compiler values -// -// -// Indirect interpreter DEFinition entrypoint -// -struc t_defentry - byte interpjsr - word interpaddr - word bytecodeaddr - byte bytecodexbyte - byte callcount - byte bytecodesize -end -// // Private addresses // -const codemax = $A000 const cmdparser = $A0F0 -const jitcomp = $A0F2 -const jitcodeptr = $A0F4 -const sinterp = $A0F6 -const xinterp = $A0F8 -const jitinterp = $A0FA -const estkh8 = $C000 -const estkh = $00C0 -const estkl8 = $D000 -const estkl = $00D0 -const ifpl8 = $E000 -const ifph8 = $E100 -const jmptmp = $00E6 -const tmpl8 = $E700 -const tmph8 = $E800 -word directentry, indirectentry -// -// COPY FROM EXT MEM TO MAIN MEM. -// -asm defcpy(dst, defentry)#0 - !SOURCE "vmsrc/plvmzp.inc" -XPAGE = $1600 -SRCX = XPAGE+SRCH -DSTX = XPAGE+DSTH - - LDA ESTKL+1,X - STA DSTL - LDA ESTKH+1,X - STA DSTH - LDA ESTKL,X - STA TMPL - LDA ESTKH,X - STA TMPH - LDY #$05 - LDA (TMP),Y - STA SRCX - DEY - LDA (TMP),Y - STA SRCH - DEY - LDA (TMP),Y - STA SRCL - LDY #$07 - LDA (TMP),Y - TAY - DEY - BEQ + -- LDA (SRC),Y - STA (DST),Y - DEY - BNE - -+ LDA (SRC),Y - STA (DST),Y - STY SRCX - INX - INX - RTS -end -include "libsrc/jitcore.pla" // // SOS routines // FILE I/O @@ -174,10 +101,8 @@ def catalog(path)#0 entry = entry + entrylen fin for i = firstblk to entriesblk - type = ^entry - if type - len = type & $0F - ^entry = len + if ^entry + ^entry = ^entry & $0F puts(entry) type = ' ' when entry->$10 @@ -191,7 +116,7 @@ def catalog(path)#0 type = '+' wend putc(type) - for len = 18 - len downto 0 + for len = ^entry to 18 putc(' ') next filecnt-- @@ -291,7 +216,7 @@ def shell#1 volumes break is '+' - //cmdsys:modexec(striptrail(cmdptr)) + //cmdsys:modexec(striptrail(cmdptr)) return striptrail(cmdptr) //cmdsys:syswrite(cmdsys.refcons, @textmode, 3) break @@ -316,13 +241,5 @@ end // // Save pointer to command line handler // -*cmdparser = @shell -// -// Install JIT compiler -// -directentry = *sinterp -indirectentry = *xinterp -*jitcomp = @compiler -cmdsys.jitcount = 44 -cmdsys.jitsize = 96 +*cmdparser = @shell done diff --git a/src/vmsrc/apple/soscmdjit.pla b/src/vmsrc/apple/soscmdjit.pla new file mode 100755 index 0000000..eef4d83 --- /dev/null +++ b/src/vmsrc/apple/soscmdjit.pla @@ -0,0 +1,329 @@ +include "inc/cmdsys.plh" +sysflags nojitc // Keep JITC from compiling itself +// +// JIT compiler values +// +// +// Indirect interpreter DEFinition entrypoint +// +struc t_defentry + byte interpjsr + word interpaddr + word bytecodeaddr + byte bytecodexbyte + byte callcount + byte bytecodesize +end +// +// Private addresses +// +const jitcbuf = $9000 +const codemax = $A000 +const cmdparser = $A0F0 +const jitcomp = $A0F2 +const jitcodeptr = $A0F4 +const sinterp = $A0F6 +const xinterp = $A0F8 +const jitinterp = $A0FA +const estkh8 = $C000 +const estkh = $00C0 +const estkl8 = $D000 +const estkl = $00D0 +const ifpl8 = $E000 +const ifph8 = $E100 +const jmptmp = $00E6 +const tmpl8 = $E700 +const tmph8 = $E800 +word directentry, indirectentry +// +// COPY FROM EXT MEM TO MAIN MEM. +// +asm defcpy(dst, defentry)#0 + !SOURCE "vmsrc/plvmzp.inc" +XPAGE = $1600 +SRCX = XPAGE+SRCH +DSTX = XPAGE+DSTH + + LDA ESTKL+1,X + STA DSTL + LDA ESTKH+1,X + STA DSTH + LDA ESTKL,X + STA TMPL + LDA ESTKH,X + STA TMPH + LDY #$05 + LDA (TMP),Y + STA SRCX + DEY + LDA (TMP),Y + STA SRCH + DEY + LDA (TMP),Y + STA SRCL + LDY #$07 + LDA (TMP),Y + TAY + DEY + BEQ + +- LDA (SRC),Y + STA (DST),Y + DEY + BNE - ++ LDA (SRC),Y + STA (DST),Y + STY SRCX + INX + INX + RTS +end +include "libsrc/jitcore.pla" +// +// SOS routines +// FILE I/O +// +def getpfx(path)#1 + byte params[4] + + ^path = 0 + params.0 = 2 + params:1 = path + params.3 = 128 + syscall($C7, @params) + return path +end +def setpfx(path)#1 + byte params[6] + byte fileinfo[2] + + params.0 = 3 + params:1 = path + params:3 = @fileinfo + params.5 = 2 + if not syscall($C4, @params) and (fileinfo.1 == $00 or fileinfo.1 == $0F) // Make sure it's a directory + params.0 = 1 + params:1 = path + syscall($C6, @params) + else + getpfx(path) // Get current path + fin + return path +end +def dev_info(devnum, name, list, listlen)#1 + byte params[7] + + params.0 = 4 + params.1 = devnum + params:2 = name + params:4 = list + params.6 = listlen + return syscall($85, @params) +end +def volume(devname, volname)#1 + byte params[9] + + params.0 = 4 + params:1 = devname + params:3 = volname + params:5 = 0 + params:7 = 0 + return syscall($C5, @params) +end +// +// Command mode +// +def volumes()#0 + byte info[11] + byte devname[17] + byte volname[17] + byte i + + for i = $01 to $18 + if dev_info(i, @devname, @info, 11) == 0 + puts(@devname) + if volume(@devname, @volname) == 0 + puts(" => /") + puts(@volname) + putc('/') + fin + putln + fin + next +end +def catalog(path)#0 + byte refnum + byte firstblk + byte entrylen, entriesblk + byte i, type, len + word entry, filecnt, catptr + + if !^path + getpfx(path) + fin + refnum = cmdsys:sysopen(path) + if not refnum + return + fin + catptr = heapmark + firstblk = 1 + repeat + if cmdsys:sysread(refnum, catptr, 512) == 512 + entry = catptr + 4 + if firstblk + entrylen = catptr->$23 + entriesblk = catptr->$24 + filecnt = catptr=>$25 + entry = entry + entrylen + fin + for i = firstblk to entriesblk + if ^entry + ^entry = ^entry & $0F + puts(entry) + type = ' ' + when entry->$10 + is $0F // Is it a directory? + type = '/' + break + is $FF // SYSTEM file + type = '-' + break + is $FE // REL file + type = '+' + wend + putc(type) + for len = ^entry to 18 + putc(' ') + next + filecnt-- + fin + entry = entry + entrylen + next + firstblk = 0 + else + filecnt = 0 + fin + until filecnt == 0 + cmdsys:sysclose(refnum) + putln() +end +def stripchars(strptr)#1 + while ^strptr and ^(strptr + 1) > ' ' + memcpy(strptr + 1, strptr + 2, ^strptr) + ^strptr-- + loop + return ^strptr +end +def stripspaces(strptr)#0 + while ^strptr and ^(strptr + ^strptr) <= ' ' + ^strptr-- + loop + while ^strptr and ^(strptr + 1) <= ' ' + memcpy(strptr + 1, strptr + 2, ^strptr) + ^strptr-- + loop +end +def striptrail(strptr)#1 + byte i + + for i = 1 to ^strptr + if ^(strptr + i) <= ' ' + ^strptr = i - 1 + break + fin + next + return strptr +end +def parsecmd(strptr)#1 + byte cmd + + cmd = 0 + stripspaces(strptr) + if ^strptr + cmd = ^(strptr + 1) + memcpy(strptr + 1, strptr + 2, ^strptr) + ^strptr-- + fin + stripspaces(strptr) + return cmd +end +// +// Command line handler +// +def shell#1 + byte textmode[3] + byte prefix[64] + byte err[] + word cmdptr + // + // Copy AUTORUN commmand line + // + cmdptr = strcpy(heapmark, cmdsys:cmdline) + // + // Handle commands. + // + repeat + if ^cmdptr + when toupper(parsecmd(cmdptr)) + is 'C' + catalog(cmdptr) + break + is 'P' + if ^cmdptr and ^(cmdptr + 1) <> '/' + strcat(@prefix, cmdptr) + else + strcpy(@prefix, cmdptr) + fin + setpfx(@prefix) + break + is '/' + repeat + prefix-- + until prefix[prefix] == '/' + if prefix > 1 + setpfx(@prefix) + fin + break + is 'S' + setpfx(cmdptr) + strcat(getpfx(cmdsys:syspath), "SYS/")) + break + is 'V' + volumes + break + is '+' + *jitcodeptr = jitcbuf + //cmdsys:modexec(striptrail(cmdptr)) + return striptrail(cmdptr) + //cmdsys:syswrite(cmdsys.refcons, @textmode, 3) + break + otherwise + puts("?\n") + wend + if cmdsys.syserr + err = cmdsys.syserr + puts("ERR:$") + putb(err) + else + puts("OK") + fin + putln + fin + puts(getpfx(@prefix)) + cmdptr = gets($BA) + strcpy(cmdsys:cmdline, cmdptr) + until 0 + return 0 +end +// +// Save pointer to command line handler +// +*cmdparser = @shell +// +// Install JIT compiler +// +directentry = *sinterp +indirectentry = *xinterp +*jitcomp = @compiler +cmdsys.jitcount = 32 +cmdsys.jitsize = 96 +done diff --git a/src/vmsrc/apple/sossys.pla b/src/vmsrc/apple/sossys.pla index de840da..7a4250e 100755 --- a/src/vmsrc/apple/sossys.pla +++ b/src/vmsrc/apple/sossys.pla @@ -11,7 +11,6 @@ const reshgr1 = $0010 const reshgr2 = $0020 const resxhgr1 = $0040 const resxhgr2 = $0080 -const nojitc = $0100 // // Module don't free memory // @@ -23,7 +22,6 @@ const modinitkeep = $4000 const instr = $A020 const cmdparser = $A0F0 const xinterp = $A0F8 -const jitinterp = $A0FA // // Indirect interpreter DEFinition entrypoint // @@ -32,16 +30,8 @@ struc t_defentry word interpaddr word bytecodeaddr byte bytecodexbyte - byte callcount - byte bytecodesize end // -// JIT compiler values -// -const jitcomp = $A0F2 -const jitcodeptr = $A0F4 -const codemax = $A000 -// // Pedefined functions. // predef syscall(cmd,params)#1, call(addr,areg,xreg,yreg,status)#1 @@ -59,7 +49,7 @@ word syspath word cmdlnptr word = @execmod, @open, @close, @read, @write byte perr -byte jitcount = 0 +byte jitcount = 0 // Keep these here for compatibility byte jitsize = 0 byte refcons = 0 byte devcons = 0 @@ -701,7 +691,7 @@ asm lookupdef(addr, deftbl)#1 LDA SRCH STA ESTKH,X RTS -+ LDA #$08 ; T_DEFENTRY ++ LDA #$06 ; T_DEFENTRY CLC ADC SRCL STA SRCL @@ -1026,19 +1016,10 @@ def lookupextern(esd, index)#1 fin return 0 end -def adddef(isfirst, ext, addr, deflast)#1 +def adddef(ext, addr, deflast)#1 word preventry, defentry, defsize defentry = *deflast *deflast = defentry + t_defentry - if not isfirst - preventry = defentry - t_defentry - defsize = addr - preventry=>bytecodeaddr - if defsize <= jitsize - preventry=>interpaddr = *jitinterp // JSR JITINTRP - preventry->callcount = jitcount // Set JIT countdown - preventry->bytecodesize = defsize // Set size - fin - fin defentry->interpjsr = $20 // JSR defentry=>interpaddr = *xinterp // XINTERP defentry=>bytecodeaddr = addr @@ -1047,11 +1028,11 @@ def adddef(isfirst, ext, addr, deflast)#1 return defentry end def loadmod(mod)#1 - word refnum[], deffirst, rdlen, modsize, bytecode, codefix, defofst, defcnt, init, initcode[], fixup + word refnum, rdlen, modsize, bytecode, codefix, defofst, defcnt, init, initcode[], fixup word addr, defaddr, modaddr, modfix, modofst, modend word deftbl, deflast, codeseg word moddep, rld, esd, sym - byte lerr, defext, skipjit, fileinfo[], str[16], filename[33] + byte lerr, defext, fileinfo[], str[16], filename[33] byte header[128] lerr = 0 // @@ -1086,7 +1067,6 @@ def loadmod(mod)#1 // This is an EXTended RELocatable (data+bytecode) module. // systemflags = header.4 | systemflags - skipjit = header.5 & (nojitc >> 8) defofst = header:6 defcnt = header:8 init = header:10 @@ -1172,14 +1152,12 @@ def loadmod(mod)#1 // // Run through the DeFinition Dictionary. // - deffirst = 1 while ^rld == $02 // // This is a bytcode def entry - add it to the def directory. // - adddef(deffirst, defext, rld=>1 + defofst, @deflast) - deffirst = skipjit // Calculate JIT potential or not - rld = rld + 4 + adddef(defext, rld=>1 + defofst, @deflast) + rld = rld + 4 loop // // Run through the Re-Location Dictionary. @@ -1233,7 +1211,7 @@ def loadmod(mod)#1 // initcode = 0 if init - initcode = adddef(deffirst, defext, init + defofst, @deflast)() + initcode = adddef(defext, init + defofst, @deflast)() if initcode < 0 perr = -initcode fin @@ -1242,18 +1220,16 @@ def loadmod(mod)#1 end def execmod(modfile)#1 byte moddci[17] - word saveheap, savesym, saveflags, savejit + word saveheap, savesym, saveflags perr = 1 if stodci(modfile, @moddci) saveheap = heap savesym = lastsym saveflags = systemflags - savejit = *jitcodeptr if loadmod(@moddci) < modkeep lastsym = savesym heap = saveheap - *jitcodeptr = savejit while modid modid-- seg_release(modseg[modid]) @@ -1287,14 +1263,14 @@ cmdlnptr = @cmdln // Print PLASMA version // init_cons -prstr("PLASMA 2.0 Dev JITC\n")//; putb(version.1); putc('.'); putb(version.0); putln +prstr("PLASMA 2.0 DP3\n")//; putb(version.1); putc('.'); putb(version.0); putln prstr("MEM:$"); prword(availheap); crout // // Exec command line parser // loadmod(@soscmd) -modid = 0 -autorun = open("AUTORUN") +modid = 0 +autorun = open("AUTORUN") if autorun > 0 cmdln = read(autorun, @cmdln.1, 64) close(autorun) diff --git a/src/vmsrc/apple/sossysjit.pla b/src/vmsrc/apple/sossysjit.pla new file mode 100755 index 0000000..e2cdbe8 --- /dev/null +++ b/src/vmsrc/apple/sossysjit.pla @@ -0,0 +1,1309 @@ +const membank = $FFEF +const RELADDR = $1000 +// +// System flags: memory allocator screen holes. +// +const restxt1 = $0001 +const restxt2 = $0002 +const resxtxt1 = $0004 +const resxtxt2 = $0008 +const reshgr1 = $0010 +const reshgr2 = $0020 +const resxhgr1 = $0040 +const resxhgr2 = $0080 +const nojitc = $0100 +// +// Module don't free memory +// +const modkeep = $2000 +const modinitkeep = $4000 +// +// Private addresses +// +const instr = $A020 +const cmdparser = $A0F0 +const xinterp = $A0F8 +const jitinterp = $A0FA +// +// Indirect interpreter DEFinition entrypoint +// +struc t_defentry + byte interpjsr + word interpaddr + word bytecodeaddr + byte bytecodexbyte + byte callcount + byte bytecodesize +end +// +// JIT compiler values +// +const jitcbuf = $9000 +const jitcomp = $A0F2 +const jitcodeptr = $A0F4 +const codemax = $A000 +// +// Pedefined functions. +// +predef syscall(cmd,params)#1, call(addr,areg,xreg,yreg,status)#1 +predef crout()#0, cout(c)#0, prstr(s)#0, print(i)#0, prbyte(b)#0, prword(w)#0 +predef cin()#1, rdstr(p)#1, toupper(c)#1, strcpy(dst,src)#1, strcat(dst,src)#1 +predef markheap()#1, allocheap(size)#1, allocalignheap(size, pow2, freeaddr), releaseheap(newheap)#1, availheap()#1 +predef memset(addr,value,size)#0, memcpy(dst,src,size)#0 +predef uword_isgt(a,b)#1, uword_isge(a,b)#1, uword_islt(a,b)#1, uword_isle(a,b)#1, sext(a)#1, divmod(a,b)#2 +predef execmod(modfile)#1, open(path)#1, close(refnum)#1, read(refnum, buff, len)#1, write(refnum, buff, len)#1 +// +// Exported CMDSYS table +// +word version = $0200 // 02.00 +word syspath +word cmdlnptr +word = @execmod, @open, @close, @read, @write +byte perr +byte jitcount = 0 +byte jitsize = 0 +byte refcons = 0 +byte devcons = 0 +// +// String pool. +// +byte hexchar[] = '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F' +// +// Exported Machine ID. +// +byte machid = $F2 // Apple ///, 80 columns +// +// Console and textmode control characters +// +byte console[] = ".CONSOLE" +byte textmode[] = 16, 0, 15 + +// +// Working input buffer overlayed with strings table +// +byte cmdln = "" +// +// SOS.CMD as DCI string +// +byte soscmd = 'S'|$80,'O'|$80,'S'|$80,'.'|$80,'C'|$80,'M'|$80,'D'|$80,'J'|$80,'I'|$80,'T' +// +// Standard Library exported functions. +// +byte sysmodstr[] = "CMDSYS" +byte machidstr[] = "MACHID" +byte sysstr[] = "SYSCALL" +byte callstr[] = "CALL" +byte putcstr[] = "PUTC" +byte putlnstr[] = "PUTLN" +byte putsstr[] = "PUTS" +byte putistr[] = "PUTI" +byte putbstr[] = "PUTB" +byte putwstr[] = "PUTH" +byte getcstr[] = "GETC" +byte getsstr[] = "GETS" +byte toupstr[] = "TOUPPER" +byte strcpystr[] = "STRCPY" +byte strcatstr[] = "STRCAT" +byte hpmarkstr[] = "HEAPMARK" +byte hpalignstr[] = "HEAPALLOCALIGN" +byte hpallocstr[] = "HEAPALLOC" +byte hprelstr[] = "HEAPRELEASE" +byte hpavlstr[] = "HEAPAVAIL" +byte memsetstr[] = "MEMSET" +byte memcpystr[] = "MEMCPY" +byte uisgtstr[] = "ISUGT" +byte uisgestr[] = "ISUGE" +byte uisltstr[] = "ISULT" +byte uislestr[] = "ISULE" +byte sextstr[] = "SEXT" +byte divmodstr[] = "DIVMOD" +byte sysmods[] = "" // overlay sys path with exports +word exports[] = @sysmodstr, @version +word = @sysstr, @syscall +word = @callstr, @call +word = @putcstr, @cout +word = @putlnstr, @crout +word = @putsstr, @prstr +word = @putistr, @print +word = @putbstr, @prbyte +word = @putwstr, @prword +word = @getcstr, @cin +word = @getsstr, @rdstr +word = @toupstr, @toupper +word = @hpmarkstr, @markheap +word = @hpallocstr,@allocheap +word = @hpalignstr,@allocalignheap +word = @hprelstr, @releaseheap +word = @hpavlstr, @availheap +word = @memsetstr, @memset +word = @memcpystr, @memcpy +word = @strcpystr, @strcpy +word = @strcatstr, @strcat +word = @uisgtstr, @uword_isgt +word = @uisgestr, @uword_isge +word = @uisltstr, @uword_islt +word = @uislestr, @uword_isle +word = @sextstr, @sext +word = @divmodstr, @divmod +word = @machidstr, @machid +word = 0 +word sysmodsym = @exports +// +// System variables. +// +word systemflags = 0 +word heap = $2000 +byte autorun[] +byte modseg[15] +byte modid = 0 +word symtbl, lastsym +// +// CALL SOS +// SYSCALL(CMD, PARAMS) +// +asm syscall(cmd,params)#1 + LDA ESTKL,X + LDY ESTKH,X + STA PARAMS + STY PARAMS+1 + INX + LDA ESTKL,X + STA CMD + BRK +CMD !BYTE 00 +PARAMS !WORD 0000 + LDY #$00 + STA ESTKL,X + STY ESTKH,X + RTS +end +// +// CALL 6502 ROUTINE +// CALL(AREG, XREG, YREG, STATUS, ADDR) +// +asm call(addr,areg,xreg,yreg,sstatus)#1 +REGVALS = SRC + PHP + LDA ESTKL,X + STA TMPL + LDA ESTKH,X + STA TMPH + INX + LDA ESTKL,X + PHA + INX + LDY ESTKL,X + INX + LDA ESTKL+1,X + PHA + LDA ESTKL,X + INX + STX ESP + TAX + PLA + PLP + JSR JMPTMP + PHP + STA REGVALS+0 + STX REGVALS+1 + STY REGVALS+2 + PLA + STA REGVALS+3 + LDX ESP + LDA #REGVALS + STA ESTKL,X + STY ESTKH,X + PLP + RTS +end +// +// SET MEMORY TO VALUE +// MEMSET(ADDR, VALUE, SIZE) +// With optimizations from Peter Ferrie +// +asm memset(addr,value,size)#0 + LDA ESTKL+2,X + STA DSTL + LDA ESTKH+2,X + STA DSTH + LDY ESTKL,X + BEQ + + INC ESTKH,X + LDY #$00 ++ LDA ESTKH,X + BEQ SETMEX +SETMLPL CLC + LDA ESTKL+1,X +SETMLPH STA (DST),Y + DEC ESTKL,X + BEQ ++ +- INY + BEQ + +-- BCS SETMLPL + SEC + LDA ESTKH+1,X + BCS SETMLPH ++ INC DSTH + BNE -- +++ DEC ESTKH,X + BNE - +SETMEX INX + INX + INX + RTS +end +// +// COPY MEMORY +// MEMCPY(DSTADDR, SRCADDR, SIZE) +// +asm memcpy(dst,src,size)#0 + INX + INX + INX + LDA ESTKL-3,X + ORA ESTKH-3,X + BEQ CPYMEX + LDA ESTKL-2,X + CMP ESTKL-1,X + LDA ESTKH-2,X + SBC ESTKH-1,X + BCC REVCPY +; +; FORWARD COPY +; + LDA ESTKL-1,X + STA DSTL + LDA ESTKH-1,X + STA DSTH + LDA ESTKL-2,X + STA SRCL + LDA ESTKH-2,X + STA SRCH + LDY ESTKL-3,X + BEQ FORCPYLP + INC ESTKH-3,X + LDY #$00 +FORCPYLP LDA (SRC),Y + STA (DST),Y + INY + BNE + + INC DSTH + INC SRCH ++ DEC ESTKL-3,X + BNE FORCPYLP + DEC ESTKH-3,X + BNE FORCPYLP + RTS +; +; REVERSE COPY +; +REVCPY ;CLC + LDA ESTKL-3,X + ADC ESTKL-1,X + STA DSTL + LDA ESTKH-3,X + ADC ESTKH-1,X + STA DSTH + CLC + LDA ESTKL-3,X + ADC ESTKL-2,X + STA SRCL + LDA ESTKH-3,X + ADC ESTKH-2,X + STA SRCH + DEC DSTH + DEC SRCH + LDY #$FF + LDA ESTKL-3,X + BEQ REVCPYLP + INC ESTKH-3,X +REVCPYLP LDA (SRC),Y + STA (DST),Y + DEY + CPY #$FF + BNE + + DEC DSTH + DEC SRCH ++ DEC ESTKL-3,X + BNE REVCPYLP + DEC ESTKH-3,X + BNE REVCPYLP +CPYMEX RTS +end +// +// COPY FROM MAIN MEM TO EXT MEM. +// +// MEMXCPY(DSTSEG, SRC, SIZE) +// +asm memxcpy(dst,src,size)#0 + LDA ESTKL,X + ORA ESTKH,X + BEQ CPYXMEX + LDY #$00 + STY DSTL + LDA ESTKH+2,X + CLC + ADC #$60 + STA DSTH + LDA ESTKL+2,X + CLC + ADC #$7F + STA DSTX + LDA ESTKL+1,X + STA SRCL + LDA ESTKH+1,X + STA SRCH + INC ESTKH,X +CPYXLP LDA (SRC),Y + STA (DST),Y + INY + BNE + + INC DSTH + INC SRCH ++ DEC ESTKL,X + BNE CPYXLP + DEC ESTKH,X + BNE CPYXLP + LDA #$00 + STA DSTX +CPYXMEX INX + INX + INX + RTS +end +// +// POKE BYTE VAL INTO EXT MEM. +// +// XPOKEB(SEG, DST, BYTEVAL) +// +asm xpokeb(seg, dst, byteval)#0 + LDA ESTKL+1,X + STA DSTL + LDA ESTKH+1,X + CLC + ADC #$60 + STA DSTH + LDA ESTKL+2,X + CLC + ADC #$7F + STA DSTX + LDY #$00 + LDA ESTKL,X + STA (DST),Y + STY DSTX + INX + INX + INX + RTS +end +// +// Unsigned word comparisons. +// +asm uword_isge(a,b)#1 + LDA ESTKL+1,X + CMP ESTKL,X + LDA ESTKH+1,X + SBC ESTKH,X + LDA #$FF + ADC #$00 + EOR #$FF + STA ESTKL+1,X + STA ESTKH+1,X + INX + RTS +end +asm uword_isle(a,b)#1 + LDA ESTKL,X + CMP ESTKL+1,X + LDA ESTKH,X + SBC ESTKH+1,X + LDA #$FF + ADC #$00 + EOR #$FF + STA ESTKL+1,X + STA ESTKH+1,X + INX + RTS +end +asm uword_isgt(a,b)#1 + LDA ESTKL,X + CMP ESTKL+1,X + LDA ESTKH,X + SBC ESTKH+1,X + LDA #$FF + ADC #$00 + STA ESTKL+1,X + STA ESTKH+1,X + INX + RTS +end +asm uword_islt(a,b)#1 + LDA ESTKL+1,X + CMP ESTKL,X + LDA ESTKH+1,X + SBC ESTKH,X + LDA #$FF + ADC #$00 + STA ESTKL+1,X + STA ESTKH+1,X + INX + RTS +end +asm divmod(a,b)#2 + JSR INTERP ; CALL INTERP + !BYTE $36, $5C ; DIVMOD, RET +end +asm sext(a)#1 + LDY #$00 + LDA ESTKL,X + BPL + + DEY ++ STY ESTKH,X + RTS +end +// +// A DCI string is one that has the high bit set for every character except the last. +// More efficient than C or Pascal strings. +// +//def dcitos(dci, str) +// byte len, c +// len = 0 +// repeat +// c = (dci).[len] +// len = len + 1 +// (str).[len] = c & $7F +// until !(c & $80) +// ^str = len +// return len +//end +asm dcitos(dci, str)#1 + LDA ESTKL,X + STA DSTL + LDA ESTKH,X + STA DSTH + LDA ESTKL+1,X + STA SRCL + LDA ESTKH+1,X + STA SRCH + LDY #$00 +- LDA (SRC),Y + CMP #$80 + AND #$7F + INY + STA (DST),Y + BCS - + TYA + LDY #$00 + STA (DST),Y + INX + STA ESTKL,X + STY ESTKH,X + RTS +end +//def stodci(str, dci) +// byte len, c +// len = ^str +// if len == 0 +// return +// fin +// c = toupper((str).[len]) & $7F +// len = len - 1 +// (dci).[len] = c +// while len +// c = toupper((str).[len]) | $80 +// len = len - 1 +// (dci).[len] = c +// loop +// return ^str +//end +asm stodci(str, dci)#1 + LDA ESTKL,X + STA DSTL + LDA ESTKH,X + STA DSTH + LDA ESTKL+1,X + STA SRCL + LDA ESTKH+1,X + STA SRCH + INX + LDY #$00 + LDA (SRC),Y + BEQ ++ + TAY + LDA (SRC),Y + JSR TOUPR + BNE + +- LDA (SRC),Y + JSR TOUPR + ORA #$80 ++ DEY + STA (DST),Y + BNE - + LDA (SRC),Y +++ STA ESTKL,X + STY ESTKH,X + RTS +end +asm toupper(c)#1 + LDA ESTKL,X +TOUPR AND #$7F + CMP #'a' + BCC + + CMP #'z'+1 + BCS + + SBC #$1F ++ STA ESTKL,X + RTS +end +// +// Lookup routines. +// +//def lookuptbl(dci, tbl) +// word match +// while ^tbl +// match = dci +// while ^tbl == ^match +// if !(^tbl & $80) +// return (tbl):1 +// fin +// tbl = tbl + 1 +// match = match + 1 +// loop +// while (^tbl & $80) +// tbl = tbl + 1 +// loop +// tbl = tbl + 3 +// loop +// return 0 +asm lookuptbl(dci, tbl)#1 + LDY #$00 + STY DSTL + LDA ESTKH,X + CLC + ADC #$60 + STA DSTH + LDA ESTKL,X + CLC + ADC #$7F + STA DSTX + LDA ESTKL+1,X + STA SRCL + LDA ESTKH+1,X + STA SRCH +- LDA (DST),Y + BEQ + + CMP (SRC),Y + BNE ++ + INY + ASL + BCS - + LDA (DST),Y + PHA + INY + LDA (DST),Y + TAY + PLA ++ INX + STA ESTKL,X + STY ESTKH,X + LDA #$00 + STA DSTX + RTS +++ LDY #$00 +-- LDA (DST),Y + INC DSTL + BEQ + +--- ASL + BCS -- + LDA #$02 + ADC DSTL + STA DSTL + BCC - + INC DSTH + BCS - ++ INC DSTH + BNE --- +end +// def lookupidx(esd, index) +// word sym +// while ^esd +// sym = esd +// esd = sym + dcitos(sym, @str) +// if esd->0 & $10 and esd->1 == index +// return sym +// fin +// esd = esd + 3 +// loop +//end +asm lookupidx(esd, index)#1 + LDA ESTKL,X + STA TMPL + INX +--- LDA ESTKH,X + STA SRCH + LDA ESTKL,X +-- STA SRCL + LDY #$00 +- LDA (SRC),Y + BPL + + INY + BNE - ++ BEQ ++ ; END OF ESD + INY + LDA (SRC),Y + INY + AND #$10 ; EXTERN FLAG? + BEQ + + LDA (SRC),Y + CMP TMPL + BEQ +++ ; MATCH ++ INY + TYA + SEC + ADC SRCL + STA ESTKL,X ; SYM PTRL + BCC -- + INC ESTKH,X ; SYM PTRH + BNE --- +++ STA ESTKL,X ; END OF ESD + STA ESTKH,X ++++ RTS +end +//def lookupdef(addr, deftbl)#1 +// while deftbl->0 == $20 +// if deftbl=>3 == addr +// return deftbl +// fin +// deftbl = deftbl + t_defentry +// loop +// return 0 +//end +asm lookupdef(addr, deftbl)#1 + LDA ESTKH,X + STA SRCH + LDA ESTKL,X + STA SRCL + INX +- LDY #$00 + LDA (SRC),Y + CMP #$20 ; JSR OPCODE? + BNE ++ + LDY #$03 + LDA (SRC),Y + CMP ESTKL,X + BNE + + INY + LDA (SRC),Y + CMP ESTKH,X + BNE + + LDA SRCL ; MATCH + STA ESTKL,X + LDA SRCH + STA ESTKH,X + RTS ++ LDA #$08 ; T_DEFENTRY + CLC + ADC SRCL + STA SRCL + BCC - + INC SRCH + BNE - +++ STY ESTKL,X + STY ESTKH,X + RTS +end +// +// Reloc internal data +// +//def reloc(modfix, modofst, bytecode, rld)#3 +// word addr, fixup +// while ^rld +// if ^rld & $10 // EXTERN reference. +// return rld, addr, fixup +// fin +// addr = rld=>1 + modfix +// fixup = *addr + modofst +// if uword_isge(fixup, bytecode) // Bytecode address. +// return rld, addr, fixup +// fin +// *addr = fixup +// rld = rld + 4 +// loop +// return rld, addr, fixup +//end +asm reloc(modfix, modofst, bytecode, rld)#3 + LDA ESTKL,X + STA SRCL + LDA ESTKH,X + STA SRCH + LDY #$00 +- LDA (SRC),Y + BEQ RLDEX ; END OF RLD + PHA + INY + LDA (SRC),Y + INY + CLC + ADC ESTKL+3,X ; ADDR=ENTRY=>1+MODFIX + STA DSTL + LDA (SRC),Y + ADC ESTKH+3,X + STA DSTH + PLA + AND #$10 ; EXTERN REF - EXIT + BNE RLDEX + TAY ; FIXUP=*ADDR+MODOFST + LDA (DST),Y + INY + CLC + ADC ESTKL+2,X + STA TMPL + LDA (DST),Y + ADC ESTKH+2,X + CMP ESTKH+1,X ; FIXUP >= BYTECODE? + BCC + + STA TMPH + BNE RLDEX ; YEP, EXIT + LDA TMPL + CMP ESTKL+1,X + BCS RLDEX ; YEP, EXIT + LDA TMPH ++ STA (DST),Y ; *ADDR=FIXUP + DEY + LDA TMPL + STA (DST),Y + LDA SRCL ; NEXT ENTRY +; CLC + ADC #$04 + STA SRCL + BCC - + INC SRCH + BNE - +RLDEX INX + LDA TMPL + STA ESTKL,X + LDA TMPH + STA ESTKH,X + LDA DSTL + STA ESTKL+1,X + LDA DSTH + STA ESTKH+1,X + LDA SRCL + STA ESTKL+2,X + LDA SRCH + STA ESTKH+2,X + RTS +end +// +// SOS routines +// FILE I/O +// +def open(path)#1 + byte params[7] + + params.0 = 4 + params:1 = path + params.3 = 0 + params:4 = 0 + params.6 = 0 + perr = syscall($C8, @params) + return params.3 +end +def close(refnum)#1 + byte params[2] + + params.0 = 1 + params.1 = refnum + perr = syscall($CC, @params) + return perr +end +def read(refnum, buff, len)#1 + byte params[8] + + params.0 = 4 + params.1 = refnum + params:2 = buff + params:4 = len + params:6 = 0 + perr = syscall($CA, @params) + return params:6 +end +def write(refnum, buff, len)#1 + byte params[6] + + params.0 = 3 + params.1 = refnum + params:2 = buff + params:4 = len + perr = syscall($CB, @params) + return perr +end +// +// CONSOLE I/O +// +def dev_control(devnum, code, list)#1 + byte params[5] + + params.0 = 3 + params.1 = devnum + params.2 = code + params:3 = list + return syscall($83, @params) +end +def dev_getnum(name)#1 + byte params[4] + + params.0 = 2 + params:1 = name + params.3 = 0 + syscall($84, @params) + return params.3 +end +def init_cons()#0 + byte nlmode[2] + + refcons = open(@console) + devcons = dev_getnum(@console) + nlmode:0 = $0D80 + //nlmode.0 = $80 + //nlmode.1 = $0D + dev_control(devcons, $02, @nlmode) + write(refcons, @textmode, 3) +end +// +// MEMORY CALLS +// +def seg_find(search, pages, id)#3 + byte params[10] + + params.0 = 6 + params.1 = search + params.2 = id + params:3 = pages + params:5 = 0 + params:7 = 0 + params.9 = 0 + perr = syscall($41, @params) + return params.9, params:5, params:7 +end +def seg_release(segnum)#1 + byte params[2] + + params.0 = 1 + params.1 = segnum + perr = syscall($45, @params) + return perr +end +// +// CONSOLE I/O +// +def cout(ch)#0 + byte nc + + nc = 1 + if ch == $0D + ch = $0A0D + nc = 2 + fin + write(refcons, @ch, nc) +end +def crout()#0 + cout($0D) +end +def cin()#1 + byte ch + read(refcons, @ch, 1) + return ch & $7F +end +def prstr(str)#0 + write(refcons, str + 1, ^str) + if str->[^str] == $0D + cout($0A) + fin +end +def print(i)#0 + if i < 0; cout('-'); i = -i; fin + if i >= 10; print(i / 10); fin + cout(i % 10 + '0') +end +def rdstr(prompt)#1 + cout(prompt) + ^instr = read(refcons, instr+1, 128) + if instr->[^instr] == $0D + ^instr-- + fin + crout + return instr +end +def prbyte(v)#0 + cout(hexchar[(v >> 4) & $0F]) + cout(hexchar[v & $0F]) +end +def prword(v)#0 + prbyte(v >> 8) + prbyte(v) +end +// +// Heap routines. +// +def availheap()#1 + byte fp + return @fp - heap +end +def allocheap(size)#1 + word addr + addr = heap + heap = heap + size + if uword_isge(heap, @addr) + heap = addr + return 0 + fin + return addr +end +def allocalignheap(size, pow2, freeaddr)#1 + word align, addr + if freeaddr + *freeaddr = heap + fin + align = (1 << pow2) - 1 + addr = (heap | align) + 1 + heap = addr + size + if uword_isge(heap, @addr) + return 0 + fin + return addr +end +def markheap()#1 + return heap +end +def releaseheap(newheap)#1 + heap = newheap + return @newheap - heap +end +// +// Symbol table routines. +// +def addsym(sym, addr)#0 + while ^sym & $80 + xpokeb(symtbl.0, lastsym, ^sym) + lastsym = lastsym + 1 + sym = sym + 1 + loop + xpokeb(symtbl.0, lastsym, ^sym) + xpokeb(symtbl.0, lastsym + 1, addr.0) + xpokeb(symtbl.0, lastsym + 2, addr.1) + xpokeb(symtbl.0, lastsym + 3, 0) + lastsym = lastsym + 3 +end +// +// String routines. +// +def strcpy(dst, src)#1 + memcpy(dst+1, src+1, ^src) + ^dst = ^src + return dst +end +def strcat(dst, src)#1 + memcpy(dst + ^dst + 1, src + 1, ^src) + ^dst = ^dst + ^src + return dst +end +// +// Module routines. +// +def lookupextern(esd, index)#1 + word sym, addr + byte str[16] + sym = lookupidx(esd, index) + if sym + addr = lookuptbl(sym, symtbl) + if !addr + perr = $81 + dcitos(sym, @str) + cout('?'); prstr(@str); crout + fin + return addr + fin + return 0 +end +def adddef(isfirst, ext, addr, deflast)#1 + word preventry, defentry, defsize + defentry = *deflast + *deflast = defentry + t_defentry + if not isfirst + preventry = defentry - t_defentry + defsize = addr - preventry=>bytecodeaddr + if defsize <= jitsize + preventry=>interpaddr = *jitinterp // JSR JITINTRP + preventry->callcount = jitcount // Set JIT countdown + preventry->bytecodesize = defsize // Set size + fin + fin + defentry->interpjsr = $20 // JSR + defentry=>interpaddr = *xinterp // XINTERP + defentry=>bytecodeaddr = addr + defentry->bytecodexbyte = ext + defentry->t_defentry = 0 + return defentry +end +def loadmod(mod)#1 + word refnum[], deffirst, rdlen, modsize, bytecode, codefix, defofst, defcnt, init, initcode[], fixup + word addr, defaddr, modaddr, modfix, modofst, modend + word deftbl, deflast, codeseg + word moddep, rld, esd, sym + byte lerr, defext, skipjit, fileinfo[], str[16], filename[33] + byte header[128] + lerr = 0 + // + // Read the RELocatable module header (first 128 bytes) + // + dcitos(mod, @filename) + refnum = open(@filename) + if !refnum and filename < 16 + // + // Try system path + // + refnum = open(strcpy(@filename,strcat(strcpy(@header, @sysmods), @filename))) + fin + if refnum + header.0 = 3 + header:1 = @filename + header:3 = @fileinfo + header.5 = 2 + if not syscall($C4, @header) and fileinfo.1 <> $FE // Make sure it's a REL module + close(refnum) + perr = $4A // Incompatible type + return -perr + fin + rdlen = read(refnum, @header, 128) + modsize = header:0 + moddep = @header.1 + defofst = modsize + RELADDR + defext = 0 + init = 0 + if rdlen > 4 and header:2 == $6502 // magic number + // + // This is an EXTended RELocatable (data+bytecode) module. + // + systemflags = header.4 | systemflags + skipjit = header.5 & (nojitc >> 8) + defofst = header:6 + defcnt = header:8 + init = header:10 + moddep = @header.12 + // + // Load module dependencies. + // + while ^moddep + if !lookuptbl(moddep, symtbl) + if refnum + close(refnum) + refnum = 0 + fin + if loadmod(moddep) < 0 + return -perr + fin + fin + moddep = moddep + dcitos(moddep, @str) + loop + // + // Init def table. + // + deftbl = allocheap(defcnt * t_defentry + 1) + deflast = deftbl + ^deflast = 0 + if !refnum + // + // Reset read pointer. + // + refnum = open(@filename) + rdlen = read(refnum, @header, 128) + fin + fin + // + // Alloc heap space for relocated module (data + bytecode). + // + moddep++ + modfix = moddep - @header.2 // Adjust to skip header + modsize = modsize - modfix + rdlen = rdlen - modfix - 2 + modaddr = allocheap(modsize) + memcpy(modaddr, moddep, rdlen) + // + // Read in remainder of module into memory for fixups. + // + addr = modaddr + repeat + addr = addr + rdlen + rdlen = read(refnum, addr, 4096) + until rdlen <= 0 + close(refnum) + // + // Add module to symbol table. + // + addsym(mod, modaddr) + // + // Apply all fixups and symbol import/export. + // + modfix = modaddr - modfix + modofst = modfix - RELADDR + modend = modaddr + modsize + bytecode = defofst + modofst + rld = modend // Re-Locatable Directory + esd = rld // Extern+Entry Symbol Directory + while ^esd // Scan to end of ESD + esd = esd + 4 + loop + esd++ + if defcnt + // + // Locate bytecode defs in allocated segment. + // + modseg[modid], codeseg, drop = seg_find($00, (rld - bytecode + 255) >> 8, modid + $12) + if perr + return -perr + fin + modid++ + defext = codeseg.0 + $7F // (codeseg.0 | $80) - 1 + defaddr = (codeseg & $FF00) + $6000 + codefix = defaddr - bytecode + defofst = defaddr - defofst + fin + // + // Run through the DeFinition Dictionary. + // + deffirst = 1 + while ^rld == $02 + // + // This is a bytcode def entry - add it to the def directory. + // + adddef(deffirst, defext, rld=>1 + defofst, @deflast) + deffirst = skipjit // Calculate JIT potential or not + rld = rld + 4 + loop + // + // Run through the Re-Location Dictionary. + // + while ^rld + rld, addr, fixup = reloc(modfix, modofst, bytecode, rld) + if ^rld + *addr = ^rld & $10 ?? *addr + lookupextern(esd, rld->3) :: lookupdef(fixup + codefix, deftbl) + rld = rld + 4 + fin + loop + // + // Run through the External/Entry Symbol Directory. + // + while ^esd + sym = esd + esd = esd + dcitos(esd, @str) + if ^esd & $08 + // + // EXPORT symbol - add it to the global symbol table. + // + addr = esd=>1 + modofst + if uword_isge(addr, bytecode) + // + // Use the def directory address for bytecode. + // + addr = lookupdef(addr + codefix, deftbl) + fin + addsym(sym, addr) + fin + esd = esd + 3 + loop + if defext + // + // Copy bytecode to code segment. + // + memxcpy(codeseg, bytecode, modsize - (bytecode - modaddr)) + fin + else + lerr = $46 + fin + if lerr + return -lerr + fin + // + // Free up end-of-module main memory. + // + releaseheap(bytecode) + // + // Call init routine if it exists. + // + initcode = 0 + if init + initcode = adddef(deffirst, defext, init + defofst, @deflast)() + if initcode < 0 + perr = -initcode + fin + fin + return initcode +end +def execmod(modfile)#1 + byte moddci[17] + word saveheap, savesym, saveflags + + perr = 1 + if stodci(modfile, @moddci) + saveheap = heap + savesym = lastsym + saveflags = systemflags + if loadmod(@moddci) < modkeep + lastsym = savesym + heap = saveheap + while modid + modid-- + seg_release(modseg[modid]) + loop + xpokeb(symtbl.0, lastsym, 0) + systemflags = saveflags + else + modid = 0 + fin + fin + return -perr +end +// +// Init 2K symbol table. +// +drop, symtbl, drop = seg_find($00, $08, $11) +lastsym = symtbl & $FF00 +xpokeb(symtbl.0, lastsym, 0) +while *sysmodsym + stodci(sysmodsym=>0, heap) + addsym(heap, sysmodsym=>2) + sysmodsym = sysmodsym + 4 +loop +// +// Clear system path and command line +// +sysmods = 0 +syspath = @sysmods +cmdlnptr = @cmdln +// +// Print PLASMA version +// +init_cons +prstr("PLASMA 2.0 DP3 JITC\n")//; putb(version.1); putc('.'); putb(version.0); putln +prstr("MEM:$"); prword(availheap); crout +// +// Exec command line parser +// +loadmod(@soscmd) +modid = 0 +autorun = open("AUTORUN") +if autorun > 0 + cmdln = read(autorun, @cmdln.1, 64) + close(autorun) +fin +// +// Call cmd line parser +// +repeat + execmod((*cmdparser)()) + write(refcons, @textmode, 3) + cmdln = 0 +until 0 +done