Programming in Basic on Bare Metal Tutorial 3


34 posts   Page 2 of 2   1, 2
by DexOS » Thu Aug 09, 2012 6:27 pm
boz wrote:Dex - Thanks for the work your doing on this.

The term DexBasic got me a bit worried at first as I'm a bit of a low-level microcontroller coder and havent done basic since the ZX81, but now I've seen its just a bunch of smart macros covering assembly language, the tutorials were magic (except tut2 where I didnt get any serial output - I may revisit it sometime) and Macro assembly seems ideal way to get me up to speed quickly while my ARM assembly skills improve !

My ultimate goal is a recreational project to convert an old Atari ST arcade game I wrote back in the 80's but never finished, this had a lot of machine code routines, around the sprite manipulation, and I still have a lot of the notes which I'm looking forward to starting in a few months, having it instant-on is a major criteria for going bare-metal as its going in an old style arcade box

Hopefully once I'm pointed in the right direction with the graphics controller I will give it a go. two things would be nice:

1. if anyone comes up with some nice graphics/sprite assembly routines in the mean time and they could make them available that would be great.

2. The Compile -> write to SD -> boot Pi cycle is a bit slow, I may play with it on the emulator see if it speeds it up

Keep up the good work.

Thanks boz, yes the name is a bit misleading as you found out your really coding in ASM, but i hide the assembly with fasm macros , you can add assembly anywhere you want in the code.
As for the "graphics/sprite assembly routines" i know someone thats working on a bare metal GBA emulator for the PI in full assembly, that will have lot of fast optimized asm routines, i am sure there will be a demo out soon, as he is making great progress.
You can put sprites on the screen at any xy offset by using the DexBasic command:
put
http://www.dex-os.com/DexBasic/Put.htm

As for tut 2 not working, can you give me more info, was you for example using windows and what usb to serial did you use.
I have not test it on windows, as i use linux.
And as Cycl0ne pointed out you could test dwelch loader, if it needs a set offset to load to let me know and i will mod a ver of DexBasic for you.
Good luck with your Atari ST arcade games, maybe you could go the emulator route.
And make a case like this for it http://www.skpang.co.uk/blog/archives/152
That would be 8-)
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by DexOS » Thu Aug 09, 2012 10:50 pm
@pygmy_giant, this code turns one full turn counterclockwise and then one full turn clockwise in a loop.
Code: Select all
include 'DexBasic\DexBasic.inc'                   
count     = 2000                                   ; 1000
motorPin1 = GPIO17                                 ; Blue   - 28BYJ48 pin 1
motorPin2 = GPIO18                                 ; Pink   - 28BYJ48 pin 2
motorPin3 = GPIO21                                 ; Yellow - 28BYJ48 pin 3
motorPin4 = GPIO22                                 ; Orange - 28BYJ48 pin 4
                                                   ;
pinMode  GPIO17, OUTPUT                            ;
pinMode  GPIO18, OUTPUT                            ;
pinMode  GPIO21, OUTPUT                            ;
pinMode  GPIO22, OUTPUT                            ;
                                                   ;
LetsLoop:                                          ; counterclockwise
  imm32        r2,500                              ;
CounterClockWise:                                  ;
  digitalWrite motorPin4, HIGH                     ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin4, HIGH                     ;
  digitalWrite motorPin3, HIGH                     ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, HIGH                     ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, HIGH                     ;
  digitalWrite motorPin2, HIGH                     ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, HIGH                     ;
  digitalWrite motorPin1, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, HIGH                     ;
  digitalWrite motorPin1, HIGH                     ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, HIGH                     ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin4, HIGH                     ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, HIGH                     ;
  delayMicroseconds count                          ;
  subs         r2,r2, 1                            ;
  bne          CounterClockWise                    ; clockwise
                                                   ;
  digitalWrite motorPin4, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin1, LOW                      ;
                                                   ;
  imm32        r2,500                              ;
ClockWise:                                         ;
  digitalWrite motorPin1, HIGH                     ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin4, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin1, HIGH                     ;
  digitalWrite motorPin2, HIGH                     ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin4, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin1, LOW                      ;
  digitalWrite motorPin2, HIGH                     ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin4, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin1, LOW                      ;
  digitalWrite motorPin2, HIGH                     ;
  digitalWrite motorPin3, HIGH                     ;
  digitalWrite motorPin4, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin1, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin3, HIGH                     ;
  digitalWrite motorPin4, LOW                      ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin1, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin3, HIGH                     ;
  digitalWrite motorPin4, HIGH                     ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin1, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin4, HIGH                     ;
  delayMicroseconds count                          ;
                                                   ;
  digitalWrite motorPin1, HIGH                     ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin4, HIGH                     ;
  delayMicroseconds count                          ;
  subs         r2,r2, 1                            ;
  bne          ClockWise                           ; clockwise
                                                   ;
  digitalWrite motorPin1, LOW                      ;
  digitalWrite motorPin2, LOW                      ;
  digitalWrite motorPin3, LOW                      ;
  digitalWrite motorPin4, LOW                      ;
goto  LetsLoop                                   
                                                   ;
align 4                                           
ProgramSize:                                       ;
ScreenBuffer:                                      ;
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by pygmy_giant » Fri Aug 10, 2012 12:31 am
I believe you and will give it a whirl when I get back from my holidays in 10 days time.

I double dared myself to have a look on an assembly forum about conditional branches / looping and it was not all that scary, but I did not know how relevant what I was reading was to ARM architecture.

Is it possible for you to fluffy that up to look like a HL language with macros or are people like me going to have to accept that we need to learn the way of the assembler and kiss bye bye to if .. then and variabes and say 'hello' to flags and registers and conditional jumping? I might be able to live with that if the TLAs (three letter acronyms) were replaced with memorable and prouncable alternatives.

I have to say I do rather like the way that the programs start to run before I've turned my head from the wall socket to the screen - I could get used to that.
Posts: 1569
Joined: Sun Mar 04, 2012 12:49 am
by romell » Fri Aug 10, 2012 12:43 am
You could of course do most of it in c, which is what everyone but DexOS does. So no, you don't have to learn any assembly if you don't want to.

Take a look at this: viewtopic.php?f=72&t=10850 thread if you want to try some bare metal programming in c. :)
Posts: 25
Joined: Mon Jul 23, 2012 6:57 pm
by DexOS » Fri Aug 10, 2012 3:48 pm
pygmy_giant wrote:I believe you and will give it a whirl when I get back from my holidays in 10 days time.

I double dared myself to have a look on an assembly forum about conditional branches / looping and it was not all that scary, but I did not know how relevant what I was reading was to ARM architecture.

Is it possible for you to fluffy that up to look like a HL language with macros or are people like me going to have to accept that we need to learn the way of the assembler and kiss bye bye to if .. then and variabes and say 'hello' to flags and registers and conditional jumping? I might be able to live with that if the TLAs (three letter acronyms) were replaced with memorable and prouncable alternatives.

I have to say I do rather like the way that the programs start to run before I've turned my head from the wall socket to the screen - I could get used to that.

Sure i can, i can make it as readable as you want.
The code was just for my uses, so i just glued it with asm.
Have a good holiday.
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by HEX_addict » Sat Jun 21, 2014 11:13 pm

The link is not available.
Posts: 14
Joined: Wed Jun 11, 2014 12:40 pm
Location: Romania
by ShiftPlusOne » Sun Jun 22, 2014 11:08 am
HEX_addict wrote:

The link is not available.

http://web.archive.org/web/201312040145 ... esson3.htm
Doesn't seem much help though, as the actual zip file and images don't seem to be there.
Forum Moderator
Forum Moderator
Posts: 1945
Joined: Fri Jul 29, 2011 5:36 pm
Location: The unfashionable end of the western spiral arm of the Galaxy
by DexOS » Sun Jun 22, 2014 6:50 pm
As ShiftPlusOne pointed out, it seems not to have stored the images.
But the zip DexBasic.zip from here:
http://web.archive.org/web/201312040130 ... esson1.htm
Has tut 3 in the zip .
Batteries not included, Some assembly required.
User avatar
Posts: 864
Joined: Wed May 16, 2012 6:32 pm
by HEX_addict » Sun Jun 22, 2014 11:27 pm
Is not like Assembler write in BBC BASIC from RISC OS? Is a beeg diference between them?
Posts: 14
Joined: Wed Jun 11, 2014 12:40 pm
Location: Romania