English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 21 October 2019, 19:41   #21
JuanLuis
Registered User
 
Join Date: Dec 2018
Location: Málaga
Posts: 61
Quote:
Originally Posted by bebbo View Post
I adapted tutorial 9 a bit - less allocations, more use of headers...
Code:
// Scoopex Tutorial 9 for Bebbo GCC 6.5.0b

#include <proto/exec.h>
#include <graphics/gfxbase.h>
#include <hardware/cia.h>
#include <hardware/custom.h>

#include <stdint.h>
#include <string.h>

#define bool short
#define true 1
#define false 0

// omit command line parsing - smalle executable
extern void __initlibraries(void);
void __nocommandline (void){ __initlibraries();}

extern struct GfxBase * GfxBase;

extern struct Custom custom;
extern struct CIA ciaa;

#define WIDTH      320
#define HEIGHT     256
__chip uint8_t        screen_ptr[WIDTH*HEIGHT/8];
uint8_t*              smile_sprite_ptr = 0;

uint16_t*             copper_list = 0;
uint16_t*             copper_list_end = 0;

__chip uint16_t SMILE_SPRITE[] = {
	0x2C40,0x3C00, // Vstart.b,Hstart/2.b,Vstop.b,%A0000SEH

	0x07C0,0x0000, // dc.w %     *****      ,%
	0x1FF0,0x0000, // dc.w %   *********    ,%
	0x3FF8,0x0000, // dc.w %  ***********   ,%
	0x7FFC,0x0000, // dc.w % *************  ,%
	0x67CC,0x1830, // dc.w % **  *****  **  ,%   **     **
	0xE7CE,0x1830, // dc.w %***  *****  *** ,%   **     **
	0xFFFE,0x0000, // dc.w %*************** ,%
	0xFFFE,0x0000, // dc.w %*************** ,%
	0xFFFE,0x2008, // dc.w %*************** ,%  *         *
	0xFFFE,0x1830, // dc.w %*************** ,%   **     **
	0x7FFC,0x07C0, // dc.w % *************  ,%     *****
	0x7FFC,0x0000, // dc.w % *************  ,%
	0x3FF8,0x0000, // dc.w %  ***********   ,%
	0x1FF0,0x0000, // dc.w %   *********    ,%
	0x07C0,0x0000, // dc.w %     *****      ,%
	0x0000,0x0000, // dc.w %                ,%
	0,0
};

__chip uint16_t NULL_SPRITE[] = {
	0x2a20,0x2b00,
	0,0,
	0,0
};

__chip uint16_t COPPER_LIST_BEGIN[] = {
//Copper:
	0x1fc,0, // slow fetch mode, AGA compatibility
	0x100,0x0200,
	0x8e,0x2c81,
	0x90,0x2cc1,
	0x92,0x38,
	0x94,0xd0,
	0x108,0,
	0x10a,0,
	0x102,0,
	0x1a2,0xe22,
	0x1a4,0xff0,
	0x1a6,0xfff
};

__chip uint16_t SPR_P[] = {
//SprP:
	0x120, 0x0000, // Sprite 0 SMILE_SPRITE_HIGH (value is defined later)
	0x122, 0x0000, // Sprite 0 SMILE_SPRITE_LOW

	0x124, 0x0000, // Sprite 1 NULL_SPRITE_HIGH
	0x126, 0x0000, // Sprite 1 NULL_SPRITE_LOW

	0x128, 0x0000, // Sprite 2 NULL_SPRITE_HIGH
	0x12a, 0x0000, // Sprite 2 NULL_SPRITE_LOW

	0x12c, 0x0000, // Sprite 3 NULL_SPRITE_HIGH
	0x12e, 0x0000, // Sprite 3 NULL_SPRITE_LOW

	0x130, 0x0000, // Sprite 4 NULL_SPRITE_HIGH
	0x132, 0x0000, // Sprite 4 NULL_SPRITE_LOW

	0x134, 0x0000, // Sprite 5 NULL_SPRITE_HIGH
	0x136, 0x0000, // Sprite 5 NULL_SPRITE_LOW

	0x138, 0x0000, // Sprite 6 NULL_SPRITE_HIGH
	0x13a, 0x0000, // Sprite 6 NULL_SPRITE_LOW

	0x13c, 0x0000, // Sprite 7 NULL_SPRITE_HIGH
	0x13e, 0x0000  // Sprite 7 NULL_SPRITE_LOW
};

__chip uint16_t COPPER_LIST_END[] = {
//CopBplP:
	0xe0, 0x0006, // Screen HIGH WORD 0x0006 default
	0xe2, 0x0000, // Screen LOW  WORD 0x0000 default
	0x180,0x349,
	0x2b07,0xfffe,
	0x180,0x56c,
	0x2c07,0xfffe,
	0x180,0x113,
	0x100,0x1200,
	0x182,0x379,

//waitras1: // COPPER_LIST_END[18]
	0x8007,0xfffe,
	0x180,0x055, // Adjusting color entry 0 of palette for horizontal bouncing bar

//waitras2: // COPPER_LIST_END[22]
	0x8107,0xfffe,
	0x180,0x0aa, // Adjusting color entry 0 again for next color of gradient

//waitras3: // COPPER_LIST_END[26]
	0x8207,0xfffe,
	0x180,0x0ff, // Next color

//waitras4: // COPPER_LIST_END[30]
	0x8307,0xfffe,
	0x180,0x0aa, // Next color

//waitras5: // COPPER_LIST_END[34]
	0x8407,0xfffe,
	0x180,0x055, // Next color

//waitras6: // COPPER_LIST_END[38]
	0x8507,0xfffe,
	0x180,0x113, // Next color

	0xffdf,0xfffe,
	0x2c07,0xfffe,
	0x180,0x56c, // Next color
	0x2d07,0xfffe,
	0x180,0x349, // Last color of horizontal bar
	0xffff,0xfffe
};

void waitRaster(uint32_t value) {
    uint32_t mask = 0x1FF00;
    uint32_t maskedValue = (value << 8) & mask;

    while ((custom.vpos32 & mask) != maskedValue);
}

void fillScreenBuffer() {
    const size_t bitplane_size = WIDTH * HEIGHT / 8;
    uint8_t* helper = screen_ptr;

    // Inicialización del hardware
    for (uint32_t i = 0; i < bitplane_size; i++) {
        // Filling frame buffer with horizontal position of beam. Assembler version of Scoopex
        // is developed in assembler so it's faster. The look is different by this reason.
        *helper++ = custom.vhposr;
    }
}


void createCopperList() {
	copper_list = COPPER_LIST_BEGIN;

    uint16_t* spr_p_ptr = SPR_P;

    copper_list_end = COPPER_LIST_END;

    smile_sprite_ptr = (uint8_t*)SMILE_SPRITE;


    uint16_t* null_sprite_ptr = NULL_SPRITE;


    uint16_t lo_smile_sprite_ptr = ((uint32_t) smile_sprite_ptr) & 0xFFFF;
    uint16_t hi_smile_sprite_ptr = ((uint32_t) smile_sprite_ptr) >> 16;

    uint16_t lo_null_sprite_ptr = ((uint32_t) null_sprite_ptr) & 0xFFFF;
    uint16_t hi_null_sprite_ptr = ((uint32_t) null_sprite_ptr) >> 16;

    spr_p_ptr[1] = hi_smile_sprite_ptr;
    spr_p_ptr[3] = lo_smile_sprite_ptr;

    for (int i = 0; i < 7; i++) {
        spr_p_ptr[5 + i * 4] = hi_null_sprite_ptr;
        spr_p_ptr[7 + i * 4] = lo_null_sprite_ptr;
    }

    uint16_t lo_screen_ptr = ((uint32_t) screen_ptr) & 0xFFFF;
    uint16_t hi_screen_ptr = ((uint32_t) screen_ptr) >> 16;
    copper_list_end[1] = hi_screen_ptr;
    copper_list_end[3] = lo_screen_ptr;
}


void setCopperList(uint16_t* cl) {
    custom.cop1lc = (ULONG)cl;
}

void waitFrame() {
    do {
        while (custom.vposr & 1);
    } while (custom.vhposr_h != 0x2a);
}

void waitFrame2() {
    while (custom.vhposr_h != 0x2a);
}

bool leftClick() {
    return (ciaa.ciapra & (1 << 6)) == 0;
}

int main(int argc, char** argv) {
        struct copinit* copinit = GfxBase->copinit;

        uint16_t old_INTENA = custom.intenar;
        uint16_t old_DMACON = custom.dmaconr;

        waitRaster(0x0138);

        custom.intena = 0x7FFF; // Disable all bits in INTENA
        custom.intreq = 0x7FFF; // Idem
        custom.intreq = 0x7FFF; // Idem
        //*INTREQW = 0x7FFF; // Idem. Original Scoopex code do this twice. I have removed without problems.
        custom.dmacon = 0x7FFF; // Disable all bits in DMACON
        custom.dmacon = 0x87E0; // Setting DMA channels

        fillScreenBuffer(); // It's important to create screen buffer before Copper list
        createCopperList();
        setCopperList(copper_list);

        // Wait loop
        bool bar_lowering  = true;
        uint8_t bar_y_position = 0xAC;

        while (true) {
            waitFrame();
            waitFrame2();

            // Add 1 to sprite position (Smile icon)
            smile_sprite_ptr[1]++;
            bar_y_position = bar_lowering ? bar_y_position + 1 : bar_y_position - 1;

            if (bar_y_position >= 0xF0)
                bar_lowering = false;

            if (bar_y_position <= 0x40)
                bar_lowering = true;

            *((uint8_t*) &copper_list_end[18]) = bar_y_position;
            *((uint8_t*) &copper_list_end[22]) = bar_y_position + 1;
            *((uint8_t*) &copper_list_end[26]) = bar_y_position + 2;
            *((uint8_t*) &copper_list_end[30]) = bar_y_position + 3;
            *((uint8_t*) &copper_list_end[34]) = bar_y_position + 4;
            *((uint8_t*) &copper_list_end[38]) = bar_y_position + 5;

            // Detecting left click to exit
            if (leftClick())
                break;
        }

        custom.dmacon = 0x7FFF; // Disabling DMACON
        custom.dmacon = old_DMACON | 0x8200;
        custom.cop1lc = (uint32_t) copinit;
        custom.intena = old_INTENA | 0xC000;
    return 0;
}
Save as C-file tut9.c and use
Code:
m68k-amigaos-gcc -Os -msmall-code -fomit-frame-pointer -mcrt=nix13 tut9.c -o tut9
And you'll get a file with ~2688 file size. (stripped 1744, but no debug infos then)
[/code]

EDIT:
add -msmall-code and -fomit-frame-pointer saves few more bytes.
There is a big difference of size. My generated executable for your earlier version of GCC has 82000 bytes. I just compile with m68k-amigaos-g++ with -g option only, but it works fine!!

Bebbo, thanks for your compiler. Your compiler supports C++ STL and it's easier develop Amiga code using the power of GCC 6.4/6.5 libraries.

I think it's a very great contribution to Amiga World.
JuanLuis is offline  
Old 21 October 2019, 20:15   #22
Spec-Chum
Registered User
 
Join Date: Dec 2016
Location: England
Posts: 87
Quote:
Originally Posted by JuanLuis View Post
Bebbo, thanks for your compiler. Your compiler supports C++ STL and it's easier develop Amiga code using the power of GCC 6.4/6.5 libraries.

I think it's a very great contribution to Amiga World.
Well said mate

I literally only chose the 8.3 GCC version due to the source debugging features, and sadly I don't have enough VSCode extension knowledge to do anything about it

I know @prb28 (can you actually tag people on here?) was working on something, but it's not been updated for a few months.
Spec-Chum is offline  
Old 21 October 2019, 21:26   #23
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by Spec-Chum View Post
Well said mate

I literally only chose the 8.3 GCC version due to the source debugging features, and sadly I don't have enough VSCode extension knowledge to do anything about it

I know @prb28 (can you actually tag people on here?) was working on something, but it's not been updated for a few months.

You can also source debug with my tool chain... -> use bgdbserver.
Plus you can debug a real Amiga.
bebbo is offline  
Old 21 October 2019, 22:12   #24
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
Quote:
Originally Posted by Spec-Chum View Post
I know @prb28 (can you actually tag people on here?) was working on something, but it's not been updated for a few months.

No tag, but I scan the unread posts on EAB...


1- Install C/C++ extension and amiga assembly extension.

2- Clone this project: https://github.com/prb28/vscode-amig...ster/build-gcc
3- add all the bebbo's gcc binaries in the build-gcc directory.
4- Get the bin dir from https://github.com/prb28/vscode-amig...ses/tag/0.18.1, select it according to you os.
5- Build your workspace with ctrl (or cmd) / shift / B -> it runs the makefile. You'll have a new amiga binary in the fs-uae dir : fs-uae/hd0/hello.

6- Select the run configuration -> it will start fs-uae with gdbserver in the Startup-Sequence pointing to the amiga binary generated.
7- Place a breakpoint in the hello.c file.
8- Select the debug configuration and start it.


Still a complex procedure.
prb28 is offline  
Old 21 October 2019, 22:30   #25
bebbo
bye
 
Join Date: Jun 2016
Location: Some / Where
Posts: 680
Quote:
Originally Posted by prb28 View Post
No tag, but I scan the unread posts on EAB...


1- Install C/C++ extension and amiga assembly extension.

2- Clone this project: https://github.com/prb28/vscode-amig...ster/build-gcc
3- add all the bebbo's gcc binaries in the build-gcc directory.
4- Get the bin dir from https://github.com/prb28/vscode-amig...ses/tag/0.18.1, select it according to you os.
5- Build your workspace with ctrl (or cmd) / shift / B -> it runs the makefile. You'll have a new amiga binary in the fs-uae dir : fs-uae/hd0/hello.

6- Select the run configuration -> it will start fs-uae with gdbserver in the Startup-Sequence pointing to the amiga binary generated.
7- Place a breakpoint in the hello.c file.
8- Select the debug configuration and start it.


Still a complex procedure.

I agree, the setup is more complex.
And you can automate the deployment and bgdbserver starting, as I with Eclipse.


a) run bgdbserver in a shared folder (shared from WinUAE and the PC). Do this only once - until bgdbserver gets killed.
b) add post build steps
b1) copy the stripped file to the shared folder using m68k-amigaos-strip <program> -o <folder>/<program>, the debug info is not necessary on the Amiga side.

b2) send via tcp "gdbserver :2345; <program> [<parameters>]\r\n" where 2345 is the port number to use

b3) start m68k-amigaos-gdb <program> and issue the command "target remote :2345" (use your port number)



this connects your gdb with the bgdbserver in WinUAE.




Maybe you can automate some of these steps, as it's done in Eclipse?
bebbo is offline  
Old 21 October 2019, 23:56   #26
Spec-Chum
Registered User
 
Join Date: Dec 2016
Location: England
Posts: 87
prb28, I got it working, with a bit of tinkering.

bgdbserver could never find sys:hello when you select the "run" configuration, bgdbserver says `failed to load program sys:hello`so I added /r /n to the end of the bgdbserver command in Startup-sequence.

Also, I had to add this to launch.json, otherwise it fails with cannot find file /hello.c on windows:
Code:
            "windows": {
                "MIMode": "gdb",
                "miDebuggerPath": "${workspaceFolder}/amiga-gcc/bin/m68k-amigaos-gdb.exe",
                "sourceFileMap": {
                    "/": "${workspaceFolder}"
                },
            },
Spec-Chum is offline  
Old 22 October 2019, 10:29   #27
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
Quote:
Originally Posted by Spec-Chum View Post
prb28, I got it working, with a bit of tinkering.
I've not used it more that 10mn on a old osx, so I'm not surprised it wasn't straightforward.

Thanks for your feedback, I'll add it to the example, with more explanations on the way to prepare the workspace. It may be useful to someone else.
prb28 is offline  
Old 22 October 2019, 10:39   #28
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
Quote:
Originally Posted by bebbo View Post
I agree, the setup is more complex.
And you can automate the deployment and bgdbserver starting, as I with Eclipse.
Thanks bebbo, I'll try it but vscode default C/C++ extension doesn't deal well with gdbserver in 'host' mode. I don't know if it will be easy.
prb28 is offline  
Old 22 October 2019, 10:52   #29
Spec-Chum
Registered User
 
Join Date: Dec 2016
Location: England
Posts: 87
Quote:
Originally Posted by prb28 View Post
Thanks bebbo, I'll try it but vscode default C/C++ extension doesn't deal well with gdbserver in 'host' mode. I don't know if it will be easy.
Might be worth looking how bartman does it on his gcc 8.3 tool chain?
Spec-Chum is offline  
Old 22 October 2019, 11:07   #30
prb28
Registered User
 
Join Date: May 2018
Location: France
Posts: 246
Quote:
Originally Posted by Spec-Chum View Post
Might be worth looking how bartman does it on his gcc 8.3 tool chain?
As far as I've seen, he did it by additions in WinUAE (as it was done in fs-uae by emoon and me). When it will be integrated in the main code of WinUAE, I'll have a closer look.
prb28 is offline  
Old 22 December 2020, 12:37   #31
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Quote:
Originally Posted by kamelito View Post
Nice keep them coming one guy on YouTube was showing how to bang the Amiga HW in C but unfortunately he stopped after making 3 of them.
https://m.youtube.com/user/weiju
For those interested, he didn´t stopped..
[ Show youtube player ]
AlfaRomeo is offline  
Old 22 December 2020, 13:11   #32
kamelito
Zone Friend
 
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 1,801
Awesome, thanks for sharing.
kamelito is offline  
Old 22 December 2020, 15:27   #33
Antiriad_UK
OCS forever!
 
Antiriad_UK's Avatar
 
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
Very nice sprite explanation.
Antiriad_UK is offline  
Old 30 January 2021, 15:07   #34
Antiriad_UK
OCS forever!
 
Antiriad_UK's Avatar
 
Join Date: Mar 2019
Location: Birmingham, UK
Posts: 418
Another video on blitter area fill and line mode. Very nice visual explanations

[ Show youtube player ]
Antiriad_UK is offline  
Old 30 January 2021, 18:05   #35
kamelito
Zone Friend
 
kamelito's Avatar
 
Join Date: May 2006
Location: France
Posts: 1,801
Awesome!
kamelito is offline  
Old 30 January 2021, 20:34   #36
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Thanks for sharing.

Very good C tutorials!!
AlfaRomeo is offline  
Old 20 February 2021, 21:34   #37
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Another video from Wei-ju Wu, this time a tutorial about sound

[ Show youtube player ]
AlfaRomeo is offline  
Old 21 February 2021, 03:18   #38
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
Definitely take the tutorials and make them your own! That's the whole point!!

And also check out Wei-ju Wu's series "Amiga Hardware Programming in C"!

All but a very few languages can "poke" - DO take advantage of abstractions. Framework/compiler - you decide what helps and hinders your control over the final binary (also true for Asm to a degree).
Photon is offline  
Old 31 March 2021, 00:15   #39
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
He did it again!!

[ Show youtube player ]

Another great video with a C tutorial from Wei-ju Wu's
AlfaRomeo is offline  
Old 10 May 2021, 10:22   #40
AlfaRomeo
A1200 040 SAM440EP 667
 
AlfaRomeo's Avatar
 
Join Date: Jan 2008
Location: Lisbon / Portugal
Posts: 873
Another amazing C tutorial from Wei-ju Wu's
[ Show youtube player ]

Last edited by AlfaRomeo; 10 May 2021 at 10:35.
AlfaRomeo is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
So I 'cracked' Photon Storm. What do you guys think? MethodGit Coders. General 3 05 August 2012 02:41
Photon's A1700 Photon Hardware mods 43 25 December 2011 15:30
Photon Storm Marlon request.Old Rare Games 11 07 September 2007 19:34
asm tuts BippyM Coders. Tutorials 61 12 January 2007 15:39
Photon Storm Tim Janssen request.Old Rare Games 9 12 September 2002 22:02

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 20:18.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.10549 seconds with 16 queries