RETROTrek - Early Development Thread

All aspects of programming on the Commander X16.
Post Reply
rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

RETROTrek - Early Development Thread

Post by rje »


As a practical example, here's a hexdump of a character record from my game-in-development.

00000000  58 10 4a 4f 52 4e 20 20  20 20 20 20 20 20 20 20  |X.JORN          |
00000010  20 00 39 38 37 36 37 38  4d 34 20 50 20 20 00 00  | .987678M4 P  ..|
00000020  00 41 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.A..............|
00000030  00 00 31 30 30 30 30 30  30 31 30 30 30 30 30 30  |..10000001000000|
00000040  30 30 4b 48 41 41 4c 4f  20 20 20 20 20 20 20 20  |00KHAALO        |
00000050  20 00 39 38 37 36 37 38  55 34 20 50 20 20 00 00  | .987678U4 P  ..|
00000060  00 45 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.E..............|
00000070  00 00 30 30 30 31 30 30  30 31 30 30 30 30 30 30  |..00010001000000|
00000080  30 30 41 52 52 4c 41 4e  52 4f 55 47 48 4c 20 20  |00ARRLANROUGHL  |
00000090  20 00 39 38 37 36 37 38  56 34 20 50 20 20 00 00  | .987678V4 P  ..|
000000a0  00 50 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.P..............|
000000b0  00 00 30 31 30 30 30 30  30 31 30 30 30 30 30 30  |..01000001000000|
000000c0  30 30 54 48 52 4f 59 53  53 20 20 20 20 20 20 20  |00THROYSS       |
000000d0  20 00 39 38 37 36 37 38  44 34 20 50 20 20 00 00  | .987678D4 P  ..|
000000e0  00 53 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |.S..............|
000000f0  00 00 30 30 31 30 30 30  30 31 30 30 30 30 30 30  |..00100001000000|
00000100  30 30                                             |00|

The first two characters are throwaways that normally would indicate the target address.  Because I load to a specific address, the X16 ignores them, so I code them with the codes for ASCII "X" and the decimal 16... X16, get it?  

This means the X16 sees this as a 256 byte file.

The file itself has four records for four characters.  A 15 character name with a zero at the end; a six-digit string representing the characters "personality profile" (a displayable string); a letter denoting species ("U" is human); a character denoting number of terms served in the previous career (they're all "4" here); a readied weapon and armor; a character denoting assigned position aboard a ship ("E" is engineering, for example); and sixteen digits (stringified) representing levels in sixteen skills.

All of this is playable data, although what I need primarily is name, ship position, and skill level.

I load this file, along with the ship data and the player's game state, like so:

load "SHIP.BIN",8,1,      $A000 :rem bank1 to $A3ff
load "PLAYER.BIN",8,1,    $A400 :rem bank1 to $A4ff
load "CHARACTERS.BIN",8,1,$A500 :rem bank1 to $A5ff

I get at the player data with a long series of PEEK statements.  This is superior to a long series of READ statements, but I think reading from a SEQ file would be more convenient (for transfer to main RAM) but not convenient for memory management.  Overloading INPUT# and GET# to treat banks as input channels would make it easy to transfer data from banks to main RAM.  Thus banks become a kind of buffer to give a kind of random access to SEQ files.  But it doesn't allow direct use of banked RAM.  



 

Starsickle
Posts: 81
Joined: Mon Aug 31, 2020 12:00 am

RETROTrek - Early Development Thread

Post by Starsickle »


That's beyond my practical experience and understanding. (I see those graphs a lot, but I'm only half sure how to read them.) I am not good at systems-level allocation and Read/Write. I'd take up 40kb making sure the code for putting a single ship into and out of a stack was usable by my own self.

Of note for consideration for features, though, is the way that The C64 and BASICV2 stores strings versus storing character arrays. This should be the subject of careful consideration for the X16 and C64 sharable code, as being able to cap various string into character arrays in a practical way means that you save memory. Much like we have Byte, Short, Int, and Double in higher level languages - so it should be with Characters and Strings on these lower level systems.

Of course, there is the system's requirement for compatibility, but I'm at the point where I won't compress things any more in order to maintain readability without documentation.

I don't even really know how to read and write data and files to any given filesystem. (My early tries in the EMU did not work). I'm basically going to wait until the GitHub Issues requests are designed and built and someone does some more key work before I dive back in. Someone has to do the system-level work that people like me can take advantage of. It's just not our bag.

Immediately, the program needs its execution broken up into module files as much as possible so they can run in sequence. I grasp how this can be done, and it goes something like this:

This here would be a data allocation and static data init file:

14 REM // MC% //THE MASTER COUNTER - USED FOR PROGRAM JUMPING.
16 REM // LS% //LOADED FILE STATE - CONTROLLING THE LOADED FILE.
20 DIM RGN$(3,3,3) : DIM SCTR$(3,3,3)
21 LS%=1
22 END


which is called by the main program file below:

15 IF LS%=0 THEN : GOSUB 100 : REM //DATA NOT LOADED.
16 IF LS%=1 THEN : GOSUB 200 : REM //DATA LOADED, PROGRAM NOT.
17 IF LS%=2 THEN : GOSUB 1000 : REM //PROGRAM LOADED. GO MAIN LOOP.
18 GOTO 4000
100 REM //ROUTINE - LOAD ANOTHER FILE AND INIT DATA.
101 LOAD "INITDEMO.PRG", 8,1
200 REM //ENGINE SETUP AND INITIALIZATION=====================================
201 VN$="0.0.1" : VD$="SEPTEMBER 15TH, 2020"
202 FC%=5 : BC%=0 : FI%=0 : BI%=5 : COLOR FC%, BC%
203 SX%=640 : SY%=480
204 DIM GD%(3)
205 LS%=2
206 GOTO 1000

1000 REM //MAIN LOOP
1001 PRINT "DISPLAY SCREEN"
1002 PRINT "GET INPUT"
1003 PRINT "PROCESS INPUT"
1004 PRINT "LOOP"
1005 GOTO 1000
3000 END
4000 STOP


This is janky as hell, but I otherwise don't know how else to quickly manage program execution other than a counter or a control state variable that always hits the top of a given program file. During this, there's so many potential hazards in the program section of memory, in the call stack of memory, and all of that that I just don't know what's going on with the machine to make a safe, solid call about designing a program that is only limited by the media it's being loaded from.



I've returned to other projects, but I want to keep checking in on the X16. This kind of work is beyond my capability and patience. I don't want to give up, but I don't know if I can seriously continue short-to-mid-term.

TomXP411
Posts: 1760
Joined: Tue May 19, 2020 8:49 pm

RETROTrek - Early Development Thread

Post by TomXP411 »



1 hour ago, Starsickle said:




15 IF LS%=0 THEN : GOSUB 100 : REM //DATA NOT LOADED.

16 IF LS%=1 THEN : GOSUB 200 : REM //DATA LOADED, PROGRAM NOT.

17 IF LS%=2 THEN : GOSUB 1000 : REM //PROGRAM LOADED. GO MAIN LOOP.





The simpler syntax for this is :

ON LS% GOSUB 100,200,1000 ....



Also, try to avoid integer variables. They are actually slower in BASIC, and while they use less space to store, you actually use one byte more every time you reference it. So if you reference LS% 4 times (including setting it the first time), you actually use more space than if you just called it "LS".

 

Starsickle
Posts: 81
Joined: Mon Aug 31, 2020 12:00 am

RETROTrek - Early Development Thread

Post by Starsickle »



2 hours ago, TomXP411 said:




The simpler syntax for this is :

ON LS% GOSUB 100,200,1000 ....



Also, try to avoid integer variables. They are actually slower in BASIC, and while they use less space to store, you actually use one byte more every time you reference it. So if you reference LS% 4 times (including setting it the first time), you actually use more space than if you just called it "LS".



Will do - this is much like a Switch statement? This will save many lines, and thus many bytes.

rje
Posts: 1263
Joined: Mon Apr 27, 2020 10:00 pm
Location: Dallas Area

RETROTrek - Early Development Thread

Post by rje »



47 minutes ago, Starsickle said:




Will do - this is much like a Switch statement? This will save many lines, and thus many bytes.



That is exactly the poor man's switch statement.


Quote




I don't even really know how to read and write data and files to any given filesystem.



Sounds like we need a tutorial... and Matt can do it.

H'm, but the code I tried... failed.  I'm getting "Device not present error" when I use device 8, and "Illegal device number error" when I use device 1.  Alas.

 

Starsickle
Posts: 81
Joined: Mon Aug 31, 2020 12:00 am

RETROTrek - Early Development Thread

Post by Starsickle »



8 hours ago, rje said:




Sounds like we need a tutorial... and Matt can do it.



H'm, but the code I tried... failed.  I'm getting "Device not present error" when I use device 8, and "Illegal device number error" when I use device 1.  Alas.



Coming out of CS and programming, I'm the guy that wants everyone to document and tutorial everything, even for development. Over and over you can see that when the energy is spent to make things easier, a platform flourishes. I'd volunteer to the a wiki or a github, but there's a lot that remains unsettled and there's just some things I don't know right now.

I DO plan on posting whatever tutorials I can create myself once the program matures into a small engine for content, but getting to that point will take time. I have years of experience in Java, years of experience in scripting languages, and the most important part of that is having mature code laying around to be copied and pasted.



Heh. Maybe I should start a java project and see what can be done in two weeks with AWT/Swing, which I've grown quite sick of in Eclipse...

Ender
Posts: 220
Joined: Sat May 09, 2020 9:32 pm

RETROTrek - Early Development Thread

Post by Ender »


What is it that's not working for you guys? The LOAD statement?

SlithyMatt
Posts: 913
Joined: Tue Apr 28, 2020 2:45 am

RETROTrek - Early Development Thread

Post by SlithyMatt »



12 hours ago, rje said:




Sounds like we need a tutorial... and Matt can do it



Hey, who's controlling my content? ?

If file I/O is that challenging to folks, I can put that in the queue. The current state of the emulator and ROM is that only loading and saving whole files with the host file system is working 100%. There are still issues with the SD Card emulation and with byte-wise file I/O, so it may be a bit premature to do a deep dive.

The best practice for now is to set aside a chunk of RAM (banked RAM is perfect for this) to load your entire file into and then get the data you need by directly referencing it in memory. If your file(s) are too big to store in RAM, consider making them smaller (this is an 8-bit platform, after all!) and split them up in a way that makes sense. Some of my projects use formatted filenames so that I can programmatically select the file needed and even determine which starting bank to load it to.

TomXP411
Posts: 1760
Joined: Tue May 19, 2020 8:49 pm

RETROTrek - Early Development Thread

Post by TomXP411 »



15 hours ago, rje said:




That is exactly the poor man's switch statement.



Sounds like we need a tutorial... and Matt can do it.



H'm, but the code I tried... failed.  I'm getting "Device not present error" when I use device 8, and "Illegal device number error" when I use device 1.  Alas.



 



You have to mount an image file. The emulator cannot write directly to the file system. (I suspect that for saving to the host file system, the emulator traps LOADs and SAVEs without a device number, rather than emulating a disk drive.)

Once you do that, OPEN, GET#, INPUT#, and PRINT# work just fine on the latest version of the emulator. I've already written some code to test that and confirmed it works.

 

TomXP411
Posts: 1760
Joined: Tue May 19, 2020 8:49 pm

RETROTrek - Early Development Thread

Post by TomXP411 »



6 hours ago, Starsickle said:




Coming out of CS and programming, I'm the guy that wants everyone to document and tutorial everything, even for development. Over and over you can see that when the energy is spent to make things easier, a platform flourishes. I'd volunteer to the a wiki or a github, but there's a lot that remains unsettled and there's just some things I don't know right now.



I DO plan on posting whatever tutorials I can create myself once the program matures into a small engine for content, but getting to that point will take time. I have years of experience in Java, years of experience in scripting languages, and the most important part of that is having mature code laying around to be copied and pasted.



Heh. Maybe I should start a java project and see what can be done in two weeks with AWT/Swing, which I've grown quite sick of in Eclipse...



I've asked about this, and even volunteered to do documentation work, but @Perifractic told me that's already covered. The documentation is sparse right now, because this is a work in progress. 

As you suggest, a platform without complete documentation is difficult to develop for. But that won't be a problem here - these guys are committed to not just providing good hardware, but good documenation.

 

Post Reply