It is currently Mon Oct 20, 2014 4:34 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: HEXAROM 0.01
PostPosted: Sun Nov 04, 2012 3:36 pm 
Offline
 Profile

Joined: Tue Oct 19, 2010 7:45 am
Posts: 25
After lots of coffee I managed to create a sideways ROM version of the hex sprite routine.

For now it responds to OSBYTE &64 as demonstrated in ROMTEST, but for some reason it does not work correctly when calling from a 2nd processor.

Instructions for running on a Master:

>CHAIN "HEXAROM" : loads rom image at &8000 in bank 6
>CHAIN "HEXDEFS" : loads hex definitions (7 of them) at &A000 in bank 6

Press CTRL+BREAK to initialize the rom
*ROMS should display
...
RAM 6 HEXAROM Hex Sprites 01
...

>CHAIN "ROMTEST"

Comments and improvements welcome
To be cont'd


Attachments:
File comment: disk image
hexarom.zip [3.28 KiB]
Downloaded 7 times
hexarom1.png [296.74 KiB]
Downloaded 208 times
Top
 
 Post subject: Re: HEXAROM 0.01
PostPosted: Sat Nov 10, 2012 7:55 am 
Offline
 Profile

Joined: Tue Oct 19, 2010 7:45 am
Posts: 25
Hmmm, big time headslap :oops:

Just looked through the tube application note and noticed the OSBYTE number I used (&64) will not send the Y register across the tube. That's why it does not work correctly when called from a 2nd processor.

And it seems OSBYTE never will work as all numbers above &7F appear to be taken.

Should have thought of that before as I hit the same problem with an OSWORD call a while back.

So OSWORD it is..... Back to the drawing board.


Top
 
 Post subject: Re: HEXAROM 0.01
PostPosted: Tue Nov 13, 2012 6:48 am 
Offline
 Profile

Joined: Sat Aug 22, 2009 7:45 pm
Posts: 34
Some comments:
Code:
  150   .version EQUS " 0.01"
ROM version string must not start with any padding before it's content as you have done, it should be "a.bc" or "a.bc (de Fgh ijkl)", ie "0.01" or "0.01 (01 Jan 2012)". Also, you've got an extra zero byte after the version string. The zero byte at the start of the copyright string is the terminator of the version string. However, you /can/ have additional strings after the version string and before the copyright string, but the copyright string's zero byte terminates the previous string.

Code:
  180   EQUS "(C) pstnotpd 2012"
If there is no date in the version string, the copyright string should be "(C)year ....." not "(C) ... year" ie "(C)2012 ...." It is better to put a date in the version string, so:
Code:
  130   .title     :EQUS "HEXAROM Hex Sprites":EQUB 0
  150   .version   :EQUS "0.01 (15 Nov 2012)"
  170   .copyright :EQUB 0:EQUS "(C) pstnotpd":EQUB 0

The service handler does not need to save/restore X as X holds the ROM number and is immediately restored by the MOS on exit. Also, you must claim claimed calls by returning A set to zero, you must not restore it. Also, as OSBYTE and OSWORD pass their parameters in &EF/&F0/&F1 you don't even need to save/restore Y either.
Code:
  330   .hexosb
  340   LDA &EF:CMP#&64:BEQosb64:LDA #7:RTS
  350   :
  351   .osb64 :LDA&F0:LDX&F1:LDY#0:JSRhexer:LDA #0:RTS

As you've realised, OSBYTE less than 128 can only pass X. If you want to pass more than one byte you need to use OSWORD as all high OSBYTEs are allocated. The only spare OSBYTE is 163, but you pass an ID in X, and a parameter in Y, so that still only allows you to pass one byte of data.

On return from OSWORD you should set something in the returned control block so the calling code knows something has happened.

Code:
  380   .hexer   ASL A:STA &84
You MUST NOT corrupt external memory. You are trampling over language workspace here. &A8-&AF are reserved for this purpose, but you should preserve and restore them as you may be being called by some other code that is also using them.

Code:
  .Service
  CMP #7:BEQ ServOSByte
  CMP #8:BEQ ServOSWord
  CMP #9:BEQ ServHelp
  RTS
  :
  .ServOSWord
  LDA &EF:CMP #oswNumHexer:BEQ OswHexer
  LDA #8:RTS
  :
  .OswHexer
  LDX #7:.SaveZP
  LDA &A8,X:PHA:DEX:BPL SaveZP        :\ Save zero page workspace
  LDY #1:LDA (&F0),Y:TAX
  DEY:LDA (&F0),Y                     :\ Get parameters from control block
  JSR hexer                           :\ Perform action
  LDX #0:.RestZP
  PLA:STA &A8,X:INX:CPX #8:BNE RestZP :\ Restore zero page workspace
  LDY #2:LDA #0:STA (&F0),Y           :\ Return 'ok'
  RTS                                 :\ Return A=0, call claimed
The example code above passes the 16-bit parameter in XY+0 and XY+1 and returns a result in XY+2. This saves and restores zero page in the OSWORD handler, but if you have more service routines that use zero page workspace it's more efficient to do the save/restore in the service handler itself.

As for the actual OSWORD number, use http://beebwiki.jonripley.com/OSWORDs as a reference. OSWORDS under 128 all use a 16-byte control block, OSWORDs 128 and above use a varying length control block. It looks like for your needs a short OSWORD will be sufficient. I'd recommend &48 (72) onwards. In fact I'd recommend only a single OSWORD number, if you need additional subfunctions you should do it all through the same OSWORD, you have plenty of space in the control block to indicate the subfunction. The convention is:
XY+0 command
XY+1 result
XY+2... parameters


Top
 
 Post subject: Re: HEXAROM 0.01
PostPosted: Tue Nov 13, 2012 9:32 am 
Offline
 Profile

Joined: Tue Oct 19, 2010 7:45 am
Posts: 25
@jgharston

Tnx for the tips!

I think I'm going to dispense with the OSBYTE altogether, as I want to expose more functionality anyway. I should have at least an AND version of the hex drawing routine to allow "armies" to move over the map using masking.

There's also quite some screen real estate left over on the edges, so I want to have routines drawing half and quarter hexes.

For now I'm going for a high OSWORD as I think at some point I want to exchange map layouts over the tube, which will need some memory for the parameters.


Top
 
 Post subject: Re: HEXAROM 0.01
PostPosted: Tue Nov 13, 2012 12:31 pm 
Offline
 Profile

Joined: Sat Aug 22, 2009 7:45 pm
Posts: 34
I'd recommend OSWORD &B1, &B3 or &C2, but as long as it doesn't clash with a pre-existing call and you post an outline of your call so people are warned it's being used, it should be fine. People have been gradually creeping up from &B0 upwards. You can't use &E0 onwards as they go via USERV not to sideways ROMs. The conventional layout for the control block for a high OSWORD is:
XY+0 size of outgoing control block - required
XY+1 size of returned control block - required
XY+2 subfunction
XY+3 returned result
XY+4... parameters, word aligned for values, followed by any strings, eg:
XY+4/5/6/7 first parameter
XY+8/9/10/11 second parameter
XY+12/etc.

So, for instance, a command that takes a word and a string and just returns a yes/no result would be something like:
Code:
X%=ctrl%:Y%=X%DIV256
X%!0=9+LENstring$:REM Length of data being sent, using ! also sets X%?3 to zero
X%?1=4           :REM Length of data returned (or use X%!0=&409+LENstring$)
X%?2=function    :REM Or use eg X%!0=&120409+LENstring$ for function &12
X%!4=data%
$(X%+8)=string$
A%=oswnumber:CALL OSWORD
result=X%?3

And, OSWORDs must NEVER generate errors, in the event of a fault they MUST return a failure result so the /caller/ deals with it.


Top
 
 Post subject: Re: HEXAROM 0.01
PostPosted: Fri May 31, 2013 8:17 pm 
Offline
User avatar
 WWW  Profile

Joined: Thu Apr 03, 2008 2:49 pm
Posts: 277
Location: Antarctica
That looks great, did you have anything in mind when you wrote it?

Can't beat a bit of old school hex tiles :D


Top
 
 Post subject: Re: HEXAROM 0.01
PostPosted: Fri Jun 21, 2013 3:52 pm 
Offline
 Profile

Joined: Tue Oct 19, 2010 7:45 am
Posts: 25
Bandit Kings of Ancient China

Actually, I was thinking of re-designing the hex drawing routines to work with "quarter" hexes. That way it would be possible to rebuild actual maps from BKOAC (which I yet have to find) in mode 2. Mode 0 would probably look good too.

I got really sidetracked the past few months so not much progress.


Top
 
 Post subject: Re: HEXAROM 0.01
PostPosted: Fri Aug 09, 2013 6:48 am 
Offline
 Profile

Joined: Tue Oct 19, 2010 7:45 am
Posts: 25
Well, I guess I must kick this back to life now. :mrgreen:

Holidays coming up in an few weeks, so I'll have to dig up my design scribbles.....


Top
 
 Post subject: Re: HEXAROM 0.01
PostPosted: Fri Aug 09, 2013 6:29 pm 
Offline
User avatar
 Profile

Joined: Thu Jan 20, 2011 4:24 pm
Posts: 57
Just a suggestion ...... if you are writing the game in Basic, why not creating a HEXAROM command eg. HEXAGON par1,par2,par3,...... instead of an OSBYTE call?

Greetings
Kees


Top
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: