Assembly language text adventure

Discuss all aspects of programming here. From 8-bit through to modern architectures.
fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Assembly language text adventure

Post by fuzzel » Sun Mar 24, 2019 6:36 pm

I've decided to learn Assembly language and the best (and most enjoyable) way I can think of is to write a text adventure.
Firstly, I'm writing a routine to handle the text input and have managed to get this working, it accepts A to Z, space and backspace but I'm having trouble with carriage return. When chr$(13) is output to the screen rather than returning down to the next line it goes back to the beginning of the line instead. How do I force the text down to the next line where a response to the input will be displayed ?

User avatar
sydney
Posts: 2459
Joined: Wed May 18, 2005 9:09 am
Location: Newcastle upon Tyne
Contact:

Re: Assembly language text adventure

Post by sydney » Sun Mar 24, 2019 7:14 pm

Chr$(10) Linefeed?

User avatar
MartinB
Posts: 5252
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: Assembly language text adventure

Post by MartinB » Sun Mar 24, 2019 7:19 pm

You might find it easiest to just perform a JSR OSNEWL which will output a carriage return and new line. OSNEWL has a call address of &FFE7.

User avatar
0xC0DE
Posts: 400
Joined: Tue Mar 19, 2019 7:52 pm
Location: The Netherlands
Contact:

Re: Assembly language text adventure

Post by 0xC0DE » Sun Mar 24, 2019 7:20 pm

Learning assembly language is great!

You are outputting a carriage return (13) but you should also be outputting a line feed (10).

E.g. print character 'A', followed by carriage return and line feed:

Code: Select all

LDA #'A'
JSR $FFEE ; print character 'A'
LDA #13
JSR $FFEE ; print carriage return
LDA #10
JSR $FFEE ; print line feed
Good luck!
0xC0DE
:idea: Follow me on Twitter :idea: Visit my YouTube channel featuring my demos for Acorn Electron and BBC Micro

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Sun Mar 24, 2019 7:22 pm

Thanks, worked a treat ! Now to analyse the input. I think I'll do directions first.

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Wed Mar 27, 2019 4:06 pm

I'm now trying to do some simple arithmetic and can't see why the answer to the following is 0 rather than 1

LDA#0 - start with 0 in accum
STA&75 - store initial 0 in loc &75
ADC#65 - add 65 to accum
SBC#64 - subtract 64 from accum
STA&75 - store answer in &75

Could someone explain please ?

User avatar
hoglet
Posts: 8693
Joined: Sat Oct 13, 2012 6:21 pm
Location: Bristol
Contact:

Re: Assembly language text adventure

Post by hoglet » Wed Mar 27, 2019 4:14 pm

fuzzel wrote:
Wed Mar 27, 2019 4:06 pm
Could someone explain please ?
It's all down to the value of the carry flag (C).

Unless you indend for carry in to happen (e.g. because you are doing a 16-bit computation), then you need to
- do a CLC before the ADC (C=1 indicates carry in)
- do a SEC before the SBC (C=0 indicates borrow in)

In your example, C probably starts off at 0.

After the ADC, C is definitely 0, which causes the SBC#64 to actually subtract 65 (C=0 indicates borrow in)

Confusing, isn't it?

Dave
Last edited by hoglet on Wed Mar 27, 2019 4:17 pm, edited 3 times in total.

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Wed Mar 27, 2019 5:10 pm

Many thanks Hoglet, that's fixed it. It is a bit confusing but I will always use CLC with ADC and SEC with SBC going forward.
By the way, the program is coming along nicely, I now have text input restricted to 20 characters, only allowing A to Z, space, backspace and
carriage return. I've stored the verb (first word) separately in a location and the noun (last word) in another location for analysis.
My next step is to define subroutines for each verb, for instance NORTH, DROP, GET, INVENTORY and I have a cunning plan how to get the program to recognise each using a small amount of code. Currently the program takes up &CE bytes (my program is no doubt written pretty inefficiently).

User avatar
lurkio
Posts: 2221
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Assembly language text adventure

Post by lurkio » Wed Mar 27, 2019 8:24 pm

hoglet wrote:
Wed Mar 27, 2019 4:14 pm
... carry ... flag ... borrow in ... carry in ...

Confusing, isn't it?
Yes! A thousand times yes.

This is the sort of thing that has always made assembly seem extremely daunting to me. Will it forever be this confusing or do you get used to it and might it even become second nature (eventually)?

:?

User avatar
BigEd
Posts: 2692
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Assembly language text adventure

Post by BigEd » Wed Mar 27, 2019 8:26 pm

It's not too bad, I think. It's kind of obvious that you need to clear carry before an add, so the only thing you need to remember - and it's a very common pattern - is to set carry before a subtract. Of course, sometimes you forget, but that's a bug like any other.

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Wed Mar 27, 2019 8:32 pm

Second nature Lurkio ? I'll let you know in due course. Today I learnt to love TXA, TYA, PLA and their opposites - very useful commands indeed.
I've just been planning PROClook in Assembly while out and about. It's great being able to ponder my next moves before returning to the keyboard.
Incidentally, I've been copying my program as I go from Beebem into Notepad so I can annotate with my thoughts and explanations which is a big help.

User avatar
BigEd
Posts: 2692
Joined: Sun Jan 24, 2010 10:24 am
Location: West
Contact:

Re: Assembly language text adventure

Post by BigEd » Wed Mar 27, 2019 8:38 pm

There's a great diagram from back in the day by Bob Sander-Cederlof which might help visualise the 6502 programmer model and instruction set:
Image
(Via this post on 6502.org)

User avatar
0xC0DE
Posts: 400
Joined: Tue Mar 19, 2019 7:52 pm
Location: The Netherlands
Contact:

Re: Assembly language text adventure

Post by 0xC0DE » Wed Mar 27, 2019 8:48 pm

Nice diagram, BigEd.

Just like any other (programming) language: after much practice it will indeed become second nature.
0xC0DE
:idea: Follow me on Twitter :idea: Visit my YouTube channel featuring my demos for Acorn Electron and BBC Micro

User avatar
0xC0DE
Posts: 400
Joined: Tue Mar 19, 2019 7:52 pm
Location: The Netherlands
Contact:

Re: Assembly language text adventure

Post by 0xC0DE » Wed Mar 27, 2019 8:51 pm

fuzzel wrote:
Wed Mar 27, 2019 8:32 pm
I've been copying my program as I go from Beebem into Notepad so I can annotate with my thoughts and explanations which is a big help.
Have you tried BeebAsm? I started using it a while back and never looked back.
0xC0DE
:idea: Follow me on Twitter :idea: Visit my YouTube channel featuring my demos for Acorn Electron and BBC Micro

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Sat Mar 30, 2019 12:04 pm

In order to save space I'm using memory area &0000 to &00FF, which of these can I freely use without the operating system changing values ?

User avatar
MartinB
Posts: 5252
Joined: Mon Mar 31, 2008 9:04 pm
Location: Obscurity
Contact:

Re: Assembly language text adventure

Post by MartinB » Sat Mar 30, 2019 1:20 pm

You say to "save space" but on your assembly language learning curve, have you appreciated that the memory area you are referring to is known as 'Zero Page' (ZP) and that this is very 'special' having dedicated (memory and time saving) addressing modes associated with it? The specific locations that you can use within ZP depend on the environment of your own program but for example, if you are not going to rely on any language rom, e.g. BASIC, then you can for example use locations &0070 - &008F which are allocated to the current language. There are others you can use but as you correctly suspect, the OS uses many locations in this page so care is needed.

Here's some example (BBC Model B) ZP usage info from 8bs but note that I haven't checked it in detail for accuracy.....

8bs wrote:PAGE ZERO (&00) : OS, BASIC & USER workspace

A large part of the contents of page zero may be altered if a language
rom other than BASIC is used.

0000-0001 LOMEM (LO-HI) pointer to start of BASIC variables
0002-0003 VARTOP (LO-HI) pointer to end of BASIC variables
0004-0005 Basic stack-pointer (LO-HI)
0006-0007 HIMEM (LO-HI)
0008-0009 ERL (LO-HI)
000A BASIC text pointer offset
000B-000C Text-pointer (LO-HI)
000D-0011 RND store (5 bytes)
0012-0013 TOP (LO-HI)
0014 Number of characters in PRINT field
0015 PRINT flag: bit 7 set if PRINT output in hex
0016-0017 ERROR vector default to &B443 (LO-HI)
0018 PAGE (high byte - low byte always &00)
0019-001A Secondary BASIC text-pointer
001B Offset for secondary BASIC text-pointer
001C-001D DATA pointer - reset to PAGE
001E COUNT
001F LISTO option
0020 TRACE flag: &00=ON &01=OFF
0021-0022 Maximum TRACE number
0023 WIDTH
0024 Number of REPEATs left
0025 Number of GOSUBs left
0026 15*number of FORs left
0027 Variable type:
&00=string
&40=integer
&05=floating-point
&A4=function
&F2=procedure
&FF=real
0028 OPT value for assembler
Bit 0 list flag
Bit 1 error flag
Bit 2 relocate flag
0029-002B Assembled code buffer (3 bytes)
002A-002D Integer accumulator (IAC) (4 bytes)
2A-2B Pointer to variable
2C Variable type
&00=8 bit byte
&04=32 bit integer variable
&05=40 bit floating point variable
&80=string at a defined address
&81=dynamic string
002E-0035 Floating-point accumulator 1 (FAC#1)
2E Sign/POINT parameter
2F overflow/underflow byte
30 exponent
31-34 mantissa
35 rounding byte
0036 Length of string
0037-0038 Object location in assembler
RENUMBER pointer
Pointer for variable name in DIM
Line-crunching pointer
Action address JMP vector
0039 Length of variable name
0039-003A Number of bytes into array to find variable
Pointer to keyword table
RENUMBER/DELETE line-number
003B-003C Pointer for RENUMBER
Number of inserted spaces in LISTO
003B-0042 Floating-point accumulator 2 (FAC#2)
3B sign
3C underflow/overflow byte
3D exponent
3E-41 mantissa
42 rounding byte
003C-003D Pointer used in DEF
003D-003E Pointer used in search for line and in line-crunching
003F Array type:
&05=floating-point
&04=string
003F-0047 Hex output nibbles
0042-0047 Numeric work area
0043 Temporary store for calculating exponents
0048 Counter in series evaluation
0049 Adjustment factor for ASCII/floating-point conversion
004A Temporary store for calculating exponents
004B-004C Pointer to current variable
004D File-number temporary store
004D-004E LISTO pointer
004F INPUT flags
0050-006F Not used
0070-008F Guaranteed unused (32 bytes) with BASIC
0090-009F Econet workspace
00A0-00A7 Allocated to current NMI owner
00A8-00AF OS command workspace
00B0-00BF Filing system scratch space
00C0-00CF Filing system private space
00D0 VDU status
Bit 0 VDU 2 enabled
Bit 1 Scrolling disabled
Bit 2 Paged scrolling selected
Bit 3 Soft scrolling
Bit 4 Not used
Bit 5 VDU 5 enabled
Bit 6 Set when edit and text cursor are separated
Bit 7 Set if VDU driver disabled
00D1 Byte mask for current graphics point
00D2-00D3 Text colour bytes to be ORed and EORed into memory, respectively
00D4-00D5 As D2-D3 except for graphics colour bytes
00D6-00D7 Address of top line of current graphics character cell
00D8 Caps-lock/shift-lock
No locks: 48
Caps lock: 32
Shift lock: 16
00DA-00DF Temporary workspace
00E0-00E1 Pointer to row multiplication table, high byte first
00E2 Cassette filing system status byte
Bit 0 Set if input file open
Bit 1 Set if output file open
Bit 2 Not used
Bit 3 Set if currently *CAT
Bit 4 Not used
Bit 5 Not used
Bit 6 Set if at end of file
Bit 7 Set if end of file warning given
00E3 Cassette filing system options byte (*OPT)
00E4-00E6 General OS workspace
00E7 Auto repeat countdown timer
00E8-00E9 Pointer to input buffer used by OSWORD &01
00EA RS423 timeout counter
=1 Cassette filing system using 6850
=0 RS423 system holds 6850 but has timed out
<0 RS423 system holds 6850 but has not yet timed out
00EB Cassette critical flag
00EC Internal key number of most recently pressed key
00ED Internal key number of first key pressed of those still pressed
00EE Internal key number of character to be ignored when scanning keyboard
NOTE : EE also RAM copy of 1MHz bus register
00EF Accumulator value for most recent OSBYTE/OSWORD
00F0 X reg for most recent OSBYTE/OSWORD
00F1 Y reg for most recent OSBYTE/OSWORD
00F2-00F3 Text pointer for processing OS commands or filenames
00F4 RAM copy of currently selected ROM number
00F5 Current logical speech PHROM or ROM filing system ROM number
00F6-00F7 Address pointer into paged ROM or speech PHROM
00F8-00F9 Not used
00FA-00FB General OS workspace
00FC Accumulator saved here in IRQ routine
00FD-00FE Pointer to error message
00FF Flag: bit 7 set if ESCAPE pressed

.
Last edited by MartinB on Sat Mar 30, 2019 1:26 pm, edited 2 times in total.

User avatar
0xC0DE
Posts: 400
Joined: Tue Mar 19, 2019 7:52 pm
Location: The Netherlands
Contact:

Re: Assembly language text adventure

Post by 0xC0DE » Sat Mar 30, 2019 4:25 pm

If you're interested in reclaiming space it may help to check out the entire memory map.
0xC0DE
:idea: Follow me on Twitter :idea: Visit my YouTube channel featuring my demos for Acorn Electron and BBC Micro

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Sat Mar 30, 2019 5:49 pm

Thanks MartinB and 0XCODE, the memory map will prove very useful. Looks like I asked the question just at the right time, I'd already used &70 to &89
so I think I'll use &70 to &8F for the commonly used variables eg current location number and find another area of memory for the other much less used variables eg the rusty iron gate at location 7 (closed =1, 0= open).

User avatar
Lardo Boffin
Posts: 1710
Joined: Thu Aug 06, 2015 6:47 am
Contact:

Re: Assembly language text adventure

Post by Lardo Boffin » Sat Mar 30, 2019 7:43 pm

I kind of went the opposite way when I wrote an adventure framework in BASIC a while back (viewtopic.php?f=53&t=14770). No verb specific code or similar or game variables in specific locations - everything is generic and reusable.
The system doesn’t know that GET is GET or similar, it merely docodes the input and return a verb number (as well as adverb and two nouns) which is then looked at by the game logic.
The main framework basically consists of code to parse the input, various functions to load a room and handle inventory and a few appropriately placed functions to hold the game logic which interacts with the built in functions. A loop then calls the game logic functions until a success or end of game flag is set.
The game variables are just 256 byte values in an array with functions built in to get and set them. All of the messages and locations etc. are built in a spreadheet which produces the appropriate files to load.
A lot more effort than just writing an adventure but it does mean the framework could be very easily reused for another one.
Not saying it is a better way to go - just thought it may be of interest. :D
Atom, issue 5
BBC model B 32k issue 4, 16k sideways RAM, Watford 12 ROM board, Acorn 6502 coproc
BBC model B 32k issue 7, turboMMC, Opus Challenger 3 512k, Pi 3 coproc
USA Model B
BBC Master, Datacentre + HDD, pi co-proc, econet, NULA

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Mon Apr 08, 2019 7:30 pm

My program development is progressing nicely. I've now added an assembly language word-wrap routine which has taken three attempts but is very nearly there. The first go was straight in at the deep end assembly language programming, but this failed. The second version I wrote in Basic first but in assembly language style eg I used A% for A, X% for X, Y% for Y and ?&80 for the stack? (i.e. PHA / PLA). This got me closer but the Basic and assembly language programs both failed. Yesterday I had the brilliant idea of drawing a flow diagram first foilowed by the Basic program which worked and then the assembly language program which also worked (well, very nearly). There's one line where a word should be able to fit on but it's pushed onto the
next line. I'm assuming here that BCS > 39 ? means if A > 39 and not >=39? Debugging is much trickier in assembler than in Basic, is there a way I can
debug my code i.e. track the values of A, X and Y ? I suppose I could store them in three memory locations at a point in the program but I'd need to rerun it for each loop. Also is there a protocol for reference I should adopt when developing my modules so when I revisit my file say in 3 months I know what I was doing ? eg a process summary, list of variables inputs, list of variables outputs etc ?

User avatar
Lardo Boffin
Posts: 1710
Joined: Thu Aug 06, 2015 6:47 am
Contact:

Re: Assembly language text adventure

Post by Lardo Boffin » Mon Apr 08, 2019 8:59 pm

Aside from something like Exmon or Exmon 2 (and your plan) on the beeb there is the option of running it in Beebem and using its debug facilities.

Word wrapping is suprisingly difficult to do properly. :shock:
Atom, issue 5
BBC model B 32k issue 4, 16k sideways RAM, Watford 12 ROM board, Acorn 6502 coproc
BBC model B 32k issue 7, turboMMC, Opus Challenger 3 512k, Pi 3 coproc
USA Model B
BBC Master, Datacentre + HDD, pi co-proc, econet, NULA

User avatar
0xC0DE
Posts: 400
Joined: Tue Mar 19, 2019 7:52 pm
Location: The Netherlands
Contact:

Re: Assembly language text adventure

Post by 0xC0DE » Mon Apr 08, 2019 9:39 pm

Maybe it helps to paste a snippet of your code here? So we can look at it if you want.

Code: Select all

LDA $70
CMP #39
BCS label
BCS will jump to label if the byte value at $70 is greater than or equal to 39. Where both values are considered to be unsigned.
0xC0DE
:idea: Follow me on Twitter :idea: Visit my YouTube channel featuring my demos for Acorn Electron and BBC Micro

User avatar
lurkio
Posts: 2221
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Assembly language text adventure

Post by lurkio » Mon Apr 08, 2019 9:55 pm

Is this of any use (haven't tried it myself)..?:

IMG_4110.jpg
IMG_4111.jpg

:?:

User avatar
tricky
Posts: 3818
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Assembly language text adventure

Post by tricky » Tue Apr 09, 2019 7:33 am

When it comes to tricky bugs, I would say using an emulator's debugger is 10 to 100X faster, although it can encourage you to be lazy!
If one of your locations has an unexpected value, running b-em with a watchw will list every instruction writing to that location and the value written.
In beebem, you can have a list of named addresses in a window and watch them change as you execute each one.
Sometimes it is better to just reread your new code ;)

User avatar
lurkio
Posts: 2221
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Assembly language text adventure

Post by lurkio » Tue Apr 09, 2019 11:48 am

lurkio wrote:
Mon Apr 08, 2019 9:55 pm
Is this of any use (haven't tried it myself)..?:
I've tried it now. The algorithm isn't perfect, as you can see in this example:
The "scelerisque in." should fit onto the end of the line, and it does the first time round, but if you append a "Hello" then suddenly it doesn't!

Code: Select all

10 DIM CDE% 300
20 paddr=&70
30 saddr=&72
40 slen=&74
50 chars=&75
60 pointer=&76
70 posx=&77
80 spcpos=&78
90 cbfroff=&79
100 swidth=40
130 F.pass=0TO2ST.2
140 P%=CDE%
150 [OPT pass
380 .err BRK
390 BRK
400 EQUS"Parameter error"
410 BRK
420 .sprint LDA &600
430 BEQ err
440 LDX #1
450 STX cbfroff
460 .getstr LDA &602,X
470 CMP #128
480 BCC err
490 JSR sproc
500 DEC slen
510 JSR outstr
520 INC cbfroff
530 INC cbfroff
540 INC cbfroff
550 LDX cbfroff
560 DEC &600
570 BNE getstr
580 RTS
590 .outstr LDY #0
600 STY pointer
610 DEY
620 STY chars
630 .fndlp INY
640 INC chars
650 LDA (saddr),Y
660 CMP #32
670 BEQ spcfnd
680 CMP #27
690 BEQ spcfnd
700 CPY slen
710 BNE fndlp
720 .spcfnd STY spcpos
730 JSR hpos
740 CLC
750 LDA posx
760 ADC chars
770 CMP #swidth
780 BCC P%+5
790 JSR &FFE7
800 LDY pointer
810 .pstr LDA (saddr),Y
820 CMP #27
830 BNE not27
840 JSR &FFE7
850 LDA #32
860 JSR &FFEE
870 JSR &FFEE
880 .not27 JSR &FFEE
890 INY
900 CPY spcpos
910 BCC pstr
920 BEQ pstr
930 LDA #0
940 STA chars
950 LDY spcpos
960 CPY slen
970 BNE P%+3
980 RTS
990 INY
1000 STY pointer
1010 JMP fndlp
1020 .strerr BRK
1030 BRK
1040 EQUS"Null String"
1050 BRK
1060 .sproc PHA
1070 LDA &600,X
1080 STA paddr
1090 LDA &601,X
1100 STA paddr+1
1110 PLA
1120 LDY #0
1130 CMP #128
1140 BEQ defstr
1150 LDA (paddr),Y
1160 STA saddr
1170 INY
1180 LDA (paddr),Y
1190 STA saddr+1
1200 INY
1210 INY
1220 LDA (paddr),Y
1230 BEQ strerr
1240 STA slen
1250 RTS
1260 .defstr LDA paddr
1270 LDX paddr+1
1280 STA saddr
1290 STX saddr+1
1300 .find0D LDA (saddr),Y
1310 CMP #13
1320 BEQ eostr
1330 INY
1340 BNE find0D
1350 .eostr CPY #0
1360 BEQ strerr
1370 STY slen
1380 RTS
1390 .hpos PHA
1400 TYA
1410 PHA
1420 LDA #134
1430 JSR &FFF4
1440 PLA
1450 TAY
1460 PLA
1470 STX posx
1480 RTS
1490 ]:NEXT
1500 A$="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."+CHR$27+"Tempus urna et pharetra pharetra. Aliquam etiam erat velit scelerisque in."
1510 PRINT"-----"
1520 CALL sprint,A$
1530 PRINT"-----"
1540 A$="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."+CHR$27+"Tempus urna et pharetra pharetra. Aliquam etiam erat velit scelerisque in. Hello."
1550 CALL sprint,A$
1560 PRINT'"-----"
1600 END
:!:
Last edited by lurkio on Tue Apr 09, 2019 11:50 am, edited 1 time in total.

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Tue Apr 09, 2019 5:41 pm

I'm sufficiently happy with the code now to submit online. I've pinched a couple of locations from Lords of Time to test it.
I think I've used just about every Assembly command I know so I can't wait to learn some new ones. For my own reasons I've signified
the end of the text with &FF. Thanks to OxCODE for making it clear about BCS meaning >+ (so BCE must be <).

2$&4000="You are in your own living room, surrounded by the usual clutter of books, mags, half-full cups of cold cof fee and the remains of yesterday's lunch. All is well with the world. You can see a golden hourglass on the mantelpiece."
3?&40E3=&FF
4REM $&4000="You are on a beach in a small bay surrounded by overhanging cliffs. Breakers rock the Viking longship drawn up on the sand to the north. Exits are north and southeast.":?&40A7=&FF
8FORI%=0 TO 3 STEP3:P%=&2A00
9[OPTI%
10LDY#1:LDX#1:LDA#0:STA&76
15.startww
20LDA&3FFF,Y
30CMP#255
35BEQwwend
40CMP#32
42BEQ findnextspace
45.pchar
50CMP#&FF:BNE pchar2 - the next 3 lines ensure that if &FF is found it is changed to
51LDA#32 - to a space otherwise &FF is printed instead of a space before the last word.
52.pchar2
53JSR&FFEE
55.printchar
60INX:INY
70JMP startww
500.findnextspace
510STA&78
520STY&77:LDA#0:STA&76
530.fs1
540INC&76:INY:LDA&3FFF,Y
550CMP#32:BEQ foundspace
560CMP#&FF:BEQ foundspace
570JMP fs1
700.foundspace
710LDY&77:PHA
730TXA:CLC:ADC&76:CMP#40:BCS cret
740PLA:JMP pchar
800.cret
801PLA
805JSR&FFE7
810LDX#0:JMP printchar
820.wwend
910RTS
990]
1000NEXTI%
1010END

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Tue Apr 09, 2019 6:00 pm

And here's the Basic version, noticeably slower of course. I've tried to match up the line numbers. I wrote this version first
in Assembly Language style so I could easily (I thought!) translate it. Bleeding BCS !

2$&4000="You are in your own living room, surrounded by the usual clutter of books, mags, half-full cups of cold coffee
and the remains of yesterday's lunch. All is well with the world. You can see a golden hourglass on the mantelpiece."
3?&40E3=&FF
10Y%=1:X%=1:?&76=0
15REM .startww
20A%=?(&3FFF+Y%)
30IFA%=&FF THEN GOTO 1000
40IFA%=32 THEN GOTO 500
45.pchar
50IFA%=&FF THEN A%=32:PRINTCHAR$(A%);:ELSEPRINTCHR$(A%); - This prevents &FF being printed instead of space
55.printchar - before the last word.
60X%=X%+1:Y%=Y%+1
70GOTO15
500REM findnextspace
510?&78=A%
520?&77=Y%:?&76=0 NOTE IN THE ASSEMBLER VERSION A IS CHANGED TO 0
530REM fs1
540?&76=?&76+1:Y%=Y%+1:A%=?(&3FFF+Y%)
550IFA%=32 THEN GOTO 700
560IFA%=&FF THEN GOTO 700
570GOTO530
700REM .foundspace
710Y%=?&77
730IF(X%+?&76)>39 THEN GOTO 800
740GOTO50
800REM .cret
805PRINT
810X%=0:GOTO55
1000END

User avatar
lurkio
Posts: 2221
Joined: Tue Apr 09, 2013 11:30 pm
Location: Doomawangara
Contact:

Re: Assembly language text adventure

Post by lurkio » Tue Apr 09, 2019 6:24 pm

fuzzel wrote:
Tue Apr 09, 2019 5:41 pm
I'm sufficiently happy with the code now to submit online ...
Interesting that your code also sometimes does a line-break a bit early, just like the code I posted above. Here's my test string in your code:

Code: Select all

2 $&4000="Tempus urna et pharetra pharetra. Aliquam etiam erat velit scelerisque in. Hello."
3 ?(&4000+LEN$&4000)=&FF 
8FORI%=0 TO 3 STEP3:P%=&2A00 
9[OPTI% 
10LDY#1:LDX#1:LDA#0:STA&76 
15.startww 
20LDA&3FFF,Y 
30CMP#255 
35BEQwwend 
40CMP#32 
42BEQ findnextspace 
45.pchar 
50CMP#&FF:BNE pchar2 \ the next 3 lines ensure that if &FF is found it is changed to
51LDA#32	\ to a space otherwise &FF is printed instead of a space before the last word.
52.pchar2
53JSR&FFEE 
55.printchar 
60INX:INY 
70JMP startww 
500.findnextspace 
510STA&78 
520STY&77:LDA#0:STA&76 
530.fs1 
540INC&76:INY:LDA&3FFF,Y 
550CMP#32:BEQ foundspace 
560CMP#&FF:BEQ foundspace 
570JMP fs1 
700.foundspace 
710LDY&77:PHA 
730TXA:CLC:ADC&76:CMP#40:BCS cret 
740PLA:JMP pchar 
800.cret 
801PLA 
805JSR&FFE7 
810LDX#0:JMP printchar 
820.wwend 
910RTS 
990] 
1000NEXTI%
1005PRINT'"-----":CALL&2A00:PRINT'"-----"'
1010END
Run in JSBeeb:
I suppose it's a bit fiddly to delete a space at the end of a line that would overflow by 1 char..? I'm not saying this is a huge deal -- it's just a bit of a pity to sometimes "waste" a char at the end of a line, especially when you've only got forty per line to work with. Just a thought. Please ignore at your convenience.

:)

fuzzel
Posts: 464
Joined: Sun Jan 02, 2005 1:16 pm
Location: Cullercoats, North Tyneside
Contact:

Re: Assembly language text adventure

Post by fuzzel » Tue Apr 09, 2019 7:37 pm

Hi Lurkio, I was having my evening stroll ruminating about why a word at the very end of the line wouldn't fit and I had the thought that it could be because the program adds the space to the length of the word when calculating whether it has reached 40 characters. I shall look at my flowchart in the morning and hopefully work out the necessary adjustment. Thanks everyone for your thoughts and suggestions so far. After I've dug myself out of this little hole I'll either tackle inventories (the word wrap will come in very useful here) or multiple word inputs.

User avatar
tricky
Posts: 3818
Joined: Tue Jun 21, 2011 8:25 am
Contact:

Re: Assembly language text adventure

Post by tricky » Wed Apr 10, 2019 9:18 am

Great start.
Often 0 is used as a terminator so that you can BEQ (Branch EQual 0) out of a loop or BNE (Branch Not Equal 0) back to the start of a loop.
If you only have 128 "valid" values, you can do the same thing with BPL (Branch PLus)/BMI (Branch MInus).
I have also seen simple text encoding where "negative" numbers index into a words table and "positive" are characters, but I don't think that this was in an actual game, but maybe a tutorial.

Post Reply