Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6081431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:10:29+00:00 2026-05-23T11:10:29+00:00

I am wondering if there is a better way to write this: void readtcp_c(unsigned

  • 0

I am wondering if there is a better way to write this:

void readtcp_c(unsigned char c)
{
    volatile char *a;
    volatile int *p;
    volatile int *q;

    a = (char *)APPLE_REG_A;    // a = memory mapped address for REG A
    *a = c + 128;               // store c + 128 in REG A

    p = (int *)APPLE_SUB;       // p = address of 6502 sub
    *p = TCP_WRITE;             // store TCP entry point in address p

    p = (int *)SOFTCARD;        // p = address of softcard address
    q = (int *)*p;              // q = softcard address
    *q = 0;                     // write 0 to softcard address
}

IANS, I have to read/write to specific addresses. ‘a’ is simply a write to a memory mapped register (6502). The next two lines are similar, except that I am writing the address of a 6502 entry point to be used later. The last 3 lines is where I have to write a 0 to the address stored in SOFTCARD. Writing to this address triggers the call to the aforementioned entry point.

It’s the last 3 lines that I think can be shorter. Perhaps not. If the other pairs can be written as a single line that’d be great too. The code works and compiles (sdcc) without error or warning.

Thanks.

Update: I guess I could replace:

    p = (int *)SOFTCARD;            // p = address of softcard address
    q = (int *)*p;                  // q = softcard address
    *q = 0;                         // write 0 to softcard address

with:

    p = (int *)*(int *)SOFTCARD;
    *p = 0;

It compiles without warning and runs. But is it readable? Thanks again.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:10:30+00:00Added an answer on May 23, 2026 at 11:10 am

    This should do it. I just replaced the variables by their definition after adding volatile (and also a pair of parenthesis)

    void readtcp_c(unsigned char c)
    {
        *((volatile char *)APPLE_REG_A) = c + 128;
        *((volatile int *)APPLE_SUB) = TCP_WRITE;
        *((volatile int *)*((volatile int *)SOFTCARD)) = 0;
    }
    

    The compiler is perfectly capable of generating good code from your first version though. I like your step-by-step code better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering if there is a better way to write this CSS? It repeats
Just wondering if there is a better way to write the following PL/SQL piece
I'm just wondering if there's a better way of doing this in SQL Server
I was wondering if there is a better way to write recursive loops in
Is there a better way to write this code? I know it's very simple,
I was wondering if there is a better way to cope with MS-Access' inability
I'm wondering if there is a better/inbuilt way, other than using a byte buffer
I am wondering if there is away (possibly a better way) to order by
I'm wondering if there is a way to get better information about the location
I was wondering if there is a way to write a statement with multiple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.