spookt Posted January 14, 2011 Share Posted January 14, 2011 OK, ploughing through the almost translated documents. I'm trying to do basic things 1st. I have the following code: PRINTF smb 'PRINTF' U_GONOFF smb 'U_GONOFF' U_SFAIL smb 'U_SFAIL' OPT S + blk sparta $5000 lda <use ldx >use jsr U_SFAIL jsr U_GONOFF bcs on jsr PRINTF dta c'You turned me OFF:(',b($9b,0) jmp ex on jsr PRINTF dta c'You turned me ON ',b($9b,0) ex rts use jsr PRINTF dta c'Usage: ONOFF.XEX ON/OFF',b($9b,0) rts Which just makes use of some SDX library calls to read the command line. I originally wrote it as a relocatable block like this: PRINTF smb 'PRINTF' U_GONOFF smb 'U_GONOFF' U_SFAIL smb 'U_SFAIL' OPT S + blk reloc main lda <use ldx >use jsr U_SFAIL ... ... blk update address I think what happens is that a and x get the relocation offsets instead of high and low byte of the relocated addresses. Anyway I've been staring at Google translate and the semi translated MADS docs for a couple of hours and now I need to go away from it for a while All help graciously received - even if I'm being *really* stupid Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 14, 2011 Share Posted January 14, 2011 I think that might have to be LDA #<USE etc. Quote Link to comment Share on other sites More sharing options...
spookt Posted January 14, 2011 Author Share Posted January 14, 2011 (edited) I think that might have to be LDA #<USE etc. Oops, silly mistake fixed! Thanks Rybags but it's still no go. If I stick an infinite loop in just after the lda,ldx and count back from the PC I get this on dissassembly: > d 105f 105F:A9 43 LDA #$43 1061:A2 00 LDX #$00 1063:4C 63 10 JMP $1063 which is exactly what I thought was happening. The offset for use is $0043 in the assembled file so it seems the values don't get updated by the loader. Edited January 14, 2011 by spookt Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 14, 2011 Share Posted January 14, 2011 (edited) You're correct, Paul. The loader can't tell whether the lsb/msb operands are lo/hi addresses or literal values. You need to write: lda use_p ldx use_p+1 ... use: jsr PRINTF dta c'Usage: ONOFF.XEX ON/OFF',b($9b,0) rts use_p: dta v(use) USE_P is simply a pointer to USE. This uses a little more space but gets around the problem. Once you get used to having to do this, it's really no biggie. Edited January 14, 2011 by flashjazzcat Quote Link to comment Share on other sites More sharing options...
spookt Posted January 14, 2011 Author Share Posted January 14, 2011 Thanks Jon. I knew I was missing a trick. Small steps at the moment but things are starting to slot into place. Quote Link to comment Share on other sites More sharing options...
drac030 Posted January 15, 2011 Share Posted January 15, 2011 (edited) Additional note: every call to U_SFAIL, when no error occurred, should have its corresponding call to U_XFAIL. So, in your program, instead of: ex rts you need to write: ex jmp U_XFAIL This is to delete the error trap which was set by U_SFAIL. When the error occurs (and the program goes to "use" in your example) the trap is removed automatically. PS. mads allows MAC/65 syntax, which is much simpler than the QA one. Instead of: dta c'You turned me ON ',b($9b,0) write .byte 'You turned me ON ',$9b This way you'll save much typing on all these 'c', 'b', '(' and ')'. Edited January 15, 2011 by drac030 Quote Link to comment Share on other sites More sharing options...
spookt Posted January 15, 2011 Author Share Posted January 15, 2011 Thanks! I'll admit I hadn't read the entry for U_XFAIL properly yet. Quote Link to comment Share on other sites More sharing options...
drac030 Posted January 15, 2011 Share Posted January 15, 2011 .byte 'You turned me ON ',$9b Obviously, it has to be: .byte 'You turned me ON ',$9b,0 Apologies for the omission. Quote Link to comment Share on other sites More sharing options...
spookt Posted January 15, 2011 Author Share Posted January 15, 2011 (edited) In case anyone is interested I made the changes and here is the working code. As Drac030 pointed out you can use .byte instead of dta. I didn't bother to change them here since it was already typed PRINTF smb 'PRINTF' U_GONOFF smb 'U_GONOFF' U_SFAIL smb 'U_SFAIL' U_XFAIL smb 'U_XFAIL' OPT S + blk reloc main ; Set error trap - Errors will be handled by 'use' lda use_p ldx use_p+1 jsr U_SFAIL ; Test 1st parameter to see if is on or off. C flag will be set if it is on, clear if off ; and an error will be thrown if neither. jsr U_GONOFF bcs on jsr PRINTF dta c'You turned me OFF:(',b($9b,0) jmp ex on: jsr PRINTF dta c'You turned me ON ',b($9b,0) ex: jmp U_XFAIL use: jsr PRINTF dta c'Usage: ONOFF.XEX ON/OFF',b($9b,0) rts use_p: dta v(use) blk update address I have to say that the SDX library routines are great so far. The biggest challenge for me has been the lack of solid English documentation. Once I understand what the docs really say it makes alot of sense! More command line processing up next then I'm going to move onto a real (small) project which should hopefully allow me to build on what I've learned so far. Thanks for the help folks. Edited January 15, 2011 by spookt Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 20, 2011 Share Posted January 20, 2011 (edited) It's a great shame you can't say something like: widget .macro parent .word child .word prev .word next .word x .word y .byte width .word height .byte .endm button .struct widget data .word flags .byte .ends This way, structs which share common headers would be easier to amend. Structs are not nestable. BTW: well done with that first program, Paul. I'm looking forward to seeing your SDX projects. Edited January 20, 2011 by flashjazzcat Quote Link to comment Share on other sites More sharing options...
+JAC! Posted January 20, 2011 Share Posted January 20, 2011 share common headers would be easier to amend. Structs are not nestable. Just a thought: You could simply the common parts in include files and use ICL. Simple replacement for "#define" if you like. Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 20, 2011 Share Posted January 20, 2011 share common headers would be easier to amend. Structs are not nestable. Just a thought: You could simply the common parts in include files and use ICL. Simple replacement for "#define" if you like. Nice idea... just depends on ICL being syntactically correct inside of a struct. Quote Link to comment Share on other sites More sharing options...
tebe Posted January 25, 2011 Share Posted January 25, 2011 (edited) with mads 1.9.2 .struct widget parent .word child .word prev .word next .word x .word y .byte width .word height .byte .ends button .struct widget data .word flags .byte .ends .print .len button ; = $11 lda #button.widget.x ; = $08 Edited January 25, 2011 by tebe Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted January 25, 2011 Share Posted January 25, 2011 oh... what are the MADS/Mac65 versions for text strings in atascii and screen code? Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 25, 2011 Share Posted January 25, 2011 with mads 1.9.2 .struct widget parent .word child .word prev .word next .word x .word y .byte width .word height .byte .ends button .struct widget data .word flags .byte .ends .print .len button ; = $11 lda #button.widget.x ; = $08 Whoa! Can this be true! Brilliant. Quote Link to comment Share on other sites More sharing options...
Heaven/TQA Posted January 25, 2011 Share Posted January 25, 2011 sorry to ask that here... same like why the sin(...) command does not work with .byte and .word? Quote Link to comment Share on other sites More sharing options...
Rybags Posted January 25, 2011 Share Posted January 25, 2011 Mac-65 uses .SBYTE to generate internal screen character codes. AtAsm can use the same and can also do .BYTE statements with an offset applied, e.g. .BYTE +$80,"string" Quote Link to comment Share on other sites More sharing options...
tebe Posted January 25, 2011 Share Posted January 25, 2011 (edited) sorry to ask that here... same like why the sin(...) command does not work with .byte and .word? SIN work with DTA dta b(sin(1,32,128)) ; byte dta a(sin(1,32,128)) ; word dta t(sin(1,32,128)) ; long (triple) dta f(sin(1,32,128)) ; dword dta b wartość typu BYTE a wartość typu WORD v wartość typu WORD, relokowalna l młodszy bajt wartości (BYTE) h starszy bajt wartości (BYTE) t wartość typu LONG (24bit) e wartość typu LONG (24bit) f wartość typu DWORD (32bit) g wartość typu DWORD (32bit) w odwróconej kolejności c ciąg znaków ATASCII ograniczony apostrofami '' lub "", znak * na końcu spowoduje invers wartości ciągu, np. dta c'abecadlo'* d ciąg znaków INTERNAL ograniczony apostrofami '' lub "", znak * na końcu spowoduje invers wartości ciągu, np. dta d'abecadlo'* and SIN work with .BYTE, .WORD, .LONG, .DWORD .byte sin(0,32,128) .word sin(0,32,128) .long sin(0,32,128) .dword sin(0,32,128) string with invers (Quick Assembler, XASM, MADS) dta c'123ABCDEF'* ; ATASCII dta d'123ABCDEF'* ; INTERNAL mads dta '123ABCDEF' ; ATASCII '' dta "123ABCDEF" ; INTERNAL "" .byte '123ABCDEF' ; ATASCII '' .byte "123ABCDEF" ; INTERNAL "" dta c'123ABCDEF' ; ATASCII dta c"123ABCDEF" ; ATASCII dta d'123ABCDEF' ; INTERNAL dta d"123ABCDEF" ; INTERNAL additional operations with string dta 'fdlsffd'+12 ; add 12 dta 'dfsdfgsd'-8 ; sub 8 dta 'dasfsdfs'* ; invers Edited January 25, 2011 by tebe Quote Link to comment Share on other sites More sharing options...
spookt Posted January 31, 2011 Author Share Posted January 31, 2011 (edited) Slow going recently due to other commitments but found some time today to come back to this. I've managed to crack handling command line switches with U_SLASH and a jump table. Can anyone tell me the easiest way to use the contents of the accumulator in SDX's PRINTF call? If I have code like jsr PRINTF dta c'Using drive %d',b($9b,0) dta a($0001) I get "Using drive 1". What if the value I want to sub into %d is in the accumulator (in my case as the result of a call to U_GETNUM)? Is there a way in MADS to drop that straight into the code as a word or do I need to store it some place and reference it? Edited January 31, 2011 by spookt Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 31, 2011 Share Posted January 31, 2011 (edited) I think you'll just have to do an STA to an in-line parameter. i.e.: jsr u_getnum sta argument jsr printf dta c'Using drive %b',b($9b,0) argument: dta b($01) Note use of the "%b" (byte) formatting character, since we have no need for the MSB here. Edited January 31, 2011 by flashjazzcat Quote Link to comment Share on other sites More sharing options...
spookt Posted January 31, 2011 Author Share Posted January 31, 2011 I think you'll just have to do an STA to an in-line parameter. i.e.: jsr u_getnum sta argument jsr printf dta c'Using drive %b',b($9b,0) argument: dta b($01) Note use of the "%b" (byte) formatting character, since we have no need for the MSB here. Thanks Jon. Didn't quite work but pointed me in the right direction. Here's what I came up with: jsr U_GETNUM beq usage sta driven jsr PRINTF dta c'Using drive %b',b($9b,0) dta a(driven) jmp exit driven: dta b($01) Seems to work OK. Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 31, 2011 Share Posted January 31, 2011 LOL. Thanks for working around my stupid mistake. %b works with a pointer, not an in-line value. Quote Link to comment Share on other sites More sharing options...
spookt Posted January 31, 2011 Author Share Posted January 31, 2011 LOL. Thanks for working around my stupid mistake. %b works with a pointer, not an in-line value. Yes, that behaviour stumped me for a while when I started trying to use PRINTF. It doesn't help that I was writing a lot of PHP at work at the time using sprintf which does just take the values straight after the formatted text. I think my head is too full. To paraphrase Homer Simpson "Every time I learn something new, something old falls out" Quote Link to comment Share on other sites More sharing options...
flashjazzcat Posted January 31, 2011 Share Posted January 31, 2011 (edited) Haha - I know the feeling. Speaking of SPRINTF, you can use the PUT_V vector to redirect printf's output to a custom character output routine. This is how FDISK works with Drac030's VBXE driver (indeed, how it writes directly to the screen in 40 column mode also). But if you're clever, you can make printf write to a string in memory. Edited January 31, 2011 by flashjazzcat Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.