The idea I had last year was inspired by reading some articles about writing a compiler and I thought I'd be able to follow the articles and produce something for the beeb that would give a subset of BASIC with easy access to some fast sprite plotting routines. In the end I read two or three of the articles then went ahead and started so - as usual with me - its a bit of a bodge job.sydney wrote:I'd thought about doing something like this last year but decided not to as I'm a bit of a novice myself. However, with some guidance from both Jonathan and Richard maybe it'd be doable.
I'm writing it in C as, at first, it's going to be a cross compiler where code is written and compiled on a pc then transferred and ran on a beeb. My C skills are pretty limited as I've not touched it in over 15 years and even then my only experience of it was college and Uni courses. Don't expect nice structured tidily formatted code.
How it works
The source code is read a line at a time and converted to beebasm compatible assembly language. Three files are needed at the assembly stage, acornconstants.asm, the .asm file produced by the compiler and the .sub file produced by the compiler. The asm file contains the main program and any variables, strings and other data. The sub file contains subroutines for any commands used in the program. Subroutines will only be added here if the command is used in the program so as to keep the code as small as possible .
What I've done so far:
At the moment the following commands can be compilied:
- byte - a datatype for declaring variables of type byte
- word - a datatype for declaring variables of type word
- string - a datatype for declaring variables of type - needs work to include a size
- let - nothing as yet!
- print - print text of variables to the screen
- mode - set screen mode
- goto - allows program flow to jump to a label
- label - for use with goto
- begin - marks the end of the variable declaration section and start of main program
- end - marks the end of the program
- rem - comments
What I want to do soon:
- Add functionality to 'let' to enable arithmetic operations like +,-,*,/,=
- Add for loop
- Add while loop
- Add repeat loop
- Add keyboard input
- Add sprite functionality
- Improve layout of assembler output so that it's more readable
What I want to do later:
- File handling
- Replace all OS routines with fast custom routines
- Write a version that will run on a beeb!
- Lots of other cool stuff!
The following beegol code...
Code: Select all
rem test program; rem should loop forever printing hello world in mode two begin; mode 2; label jump; print "hello there"; goto jump; end;
Code: Select all
\\ test program; \\ should loop forever printing hello world in mode two INCLUDE "acornconstants.asm" ORG &2000 .start lda #$16 jsr oswrch lda #2 jsr oswrch .jump \\ print lda #LO(strings0) sta printvector lda #HI(strings0) sta printvector+1 ldy #0 jsr printstring jmp jump rts INCLUDE "test.sub" .strings0 equs "hello there" equb 0 .end SAVE "MAIN",start,end
Code: Select all
.printstring lda (&F6),y beq printend jsr osasci iny bne printstring .printend rts
It is entirely possible that I'm not up to finishing this but it's been a lot of fun so far. Expect lots of questions on assembler and C!
Link to github repository: https://github.com/sydney69/beegol